javascript - jQuery - Event delegation is occuring multiple times -


i'm using event delegation in pagination website. when click < or > buttons moves page or down. problem if don't release mouse button, in split-second keep repeating click handler.

how can make event occurs once per-click? here's code:

$(document).on('mousedown', '#prev', function(event) {     // page value of url parameter 'page'     if (page != 1) {         page--;         var state = {           "thisisonpopstate": true         };         history.replacestate(state, "a", "?page=" + page + "");     }     // refresh custom function loads new items on page     refresh(); }); 

you should use "click" event instead of "mousedown" unless have unavoidable reason. "mousedown" or "touchstart" event occurs when user start pressing mouse button or screen , not fired until release button , press again.

so assume using chattering mouse or mouses has macro software. change event "click" , see if works , in case "click" event not gonna solve issue,try using mouse.

fyi,underscore methods _.throttle or _.debounce might support chattering mouses.

throttle_.throttle(function, wait, [options])

creates , returns new, throttled version of passed function, that, when invoked repeatedly, call original function @ once per every wait milliseconds. useful rate-limiting events occur faster can keep with.


debounce_.debounce(function, wait, [immediate])

creates , returns new debounced version of passed function postpone execution until after wait milliseconds have elapsed since last time invoked. useful implementing behavior should happen after input has stopped arriving. example: rendering preview of markdown comment, recalculating layout after window has stopped being resized, , on.

http://underscorejs.org/