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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With