Preventing duplicate event handlers in jQuery

I was working on some plugin development lately and ran into an issue where I needed to remove any event handlers already attached to an element before attaching a new one. I found the easiest way to do this was to simply “unbind” any previous handlers directly before binding the new one:




If you’re using a more recent jQuery version (1.7+) then you may/should be using the ‘on’ event to attach events. If this is the case then you can use ‘off’ immediately before hand to unbind the event, like so:


5 much appreciated responses...

  1. Martins says:


  2. Jorge says:

    Glad I found this little article, saved me 🙂

  3. tien says:

    thank you

  4. Anonymous says:

    Super !! this is what i was searching for

  5. Lm says:

    Love u man !!

Feel free to add your comment..

Your email address will not be published.