Unbinding jquery events after jquery live

I was working on a small project where I had to load .ascx controls using jquery. I used string writer to load the jquery html into my parent control on click.

Now I had registered event handlers for the loaded control using .live.  When I loaded the control for the first time, it was fine. But after that everytime I loaded the control, the event associated excecuted multiple times which was not supposed to happen. It looks like every time the control is loaded, the live event is registered again resulting multiple events to execute.

So the simple solution was to unbind/kill the event handle once it is registered.  So for bind, unbind is used and for “live”, “die” is used to do so.
 

$('#selector').live("click",function(){
  $(this).die();//prevents the event from binding multiple times
 //do the nessary action
});
Facebook Facebook LinkedIn LinkedIn

Leave a Comment

For Gravatar icon