You can cancel the click event before binding it again, so you only have one event associated with it:
//assuming this is a jquery object. this.unbind("click"); this.click(function(){ alert("clicked once"); });
As in jQuery 1.7, click .on now ( http://api.jquery.com/click/ ), so the correct code is now
//assuming this is a jquery object. this.off("click"); this.click(function(){ alert("clicked once"); });
This will cancel all click events (including those created by any plugins that you could use). To make sure that you only cancel the namespace for event use. ( http://api.jquery.com/off/ )
//assuming this is a jquery object. this.off("click.myApp"); this.on("click.myApp", function(){ alert("clicked once"); });
Here myApp is the namespace.
Marius Oct. 13 '09 at 5:47 2009-10-13 05:47
source share