Delay Event Plugin

by karim79

HTML

<div id="foo">Hello, click me!<div>

JavaScript

(function ($) {
    $.fn.delayEvent = function (event, callback, ms) {
        var whichjQuery = parseFloat($().jquery, 10)
            , bindMethod = whichjQuery > 1.7 ? "on" : "bind"
            , timer = 0;
        $(this)[bindMethod](event, function (event) {                   
            clearTimeout (timer);
            timer = setTimeout($.proxy(callback, this, event), ms);
        });
        return $(this);
    };
})(jQuery);

$("#foo").delayEvent("click", function () {
    alert("I will appear after one second");
}, 1000);