javascript - How to fix problems with mouseup and mousedown? -
i have following code returns 'haha' when user clicks , down. having trouble amount of times gets retuned though. first time click up/down, 'haha' gets returned once. second time go through this, gets printed twice. third time, 'haha' gets printed 3 times , on. advice on why happening? want 'haha' printed once each up/down.
$(".test").mousedown(function(){ $(".test").mouseup(function(){ console.log('haha'); }); });
you use one, event handling unbound after mouseup :
$(".test").mousedown(function(){ $(".test").one('mouseup', function(){ console.log('haha'); }); }); but seems simpler use click :
$(".test").click(function(){ console.log('haha') });
Comments
Post a Comment