Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will jquery empty() method clear the event listeners created through non jquery means

I have an element with a lot of child elements. I want to clear the content of this element and replace it with new structure.

The child elements are assigned with various event listeners and not all of those listeners are created through jquery bind method.

If I use jquery's empty method to clear the element will it remove all the event listeners or will it clear only the listeners created through jquery bind method?

like image 928
Mandai Avatar asked Nov 14 '11 10:11

Mandai


2 Answers

As several commenters have mentioned, the jQuery docs say that empty() does indeed remove event handlers: http://api.jquery.com/empty/

Perhaps that wasn't the case when this question was posted, but this page is the first hit on Google.

like image 57
TeknoFiend Avatar answered Nov 16 '22 04:11

TeknoFiend


You can unbind all listeners of a object with the .unbind() and leave the params empty

If you want to remove all the children of an element. just user $("#parent").children().remove();

With the live() and die() methods you can add eventhandlers to elements which do not yet exists yet. with $(".element").live("click", function(){}) adds a function to all .element objects that are currently in your HTML or those who are added in the future.

like image 21
Niels Avatar answered Nov 16 '22 04:11

Niels