Reputation: 3451
When an element is clicked, I want to call a function every n seconds until the mouse button is released.
How should I do this?
EDIT:
var interval,
i = 0;
$("a").on("mousedown", function(){
interval = setInterval(function(){ $(".results").append(i++); }, 250);
});
$(document.body).on("mouseup", function(){
clearInterval(interval)
});
Upvotes: 0
Views: 465
Reputation: 888117
Call setInterval
in the mousedown
handler, then call clearInterval
in mouseup
.
Upvotes: 3