I think you are looking to throttle (buffer) the clicks, that is, you want to wait a specified amount of time before you act, if the same event happens again within your throttling period, you restart your wait. http://jsfiddle.net/8QdLV/
function B() {
console.log('Clicked')
}
var timeoutId;
$('#button').click(function() {
clearTimeout(timeoutId);
timeOutId = setTimeout(B, 1000);
});
This can be generalized http://jsfiddle.net/8QdLV/
function throttle(handler, buffer) {
var timeoutId;
buffer = buffer || 1000;
return function(e) {
clearTimeout(timeoutId);
var me = this;
timeoutId = setTimeout(function() {
handler.call(me, e);
}, buffer);
}
}
$('button').click(throttle(function() {
console.log('Throttled click');
});
By the way, you may want to use https://code.google.com/p/jquery-debounce/ which also provides a $.throttle
function