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

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -