Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery, adding and removing event handlers [duplicate]

I have 2 buttons

 $(".button1").on("click", function(event){
 $(".button2").on("click", function(event){

What I would like to do is start with button1 as clicked and have no event listener, when button2 is clicked the event listener is removed and the event listener for button 1 is activated.

This is a fairly common technique is in actionscript 3 with the method removeEventListener() and would like to use a similar method or technique in jquery.

like image 545
LeBlaireau Avatar asked Apr 30 '12 14:04

LeBlaireau


1 Answers

If you want to remove an event handler bound with jQuery.on then you probably want jQuery.off

http://api.jquery.com/off/

like image 113
Petah Avatar answered Nov 02 '22 07:11

Petah