There are listeners on $('#target') and its children.
When we call $('#target').remove() to delete it from DOM,will the listeners be removed?
If not,how to remove them together?
There are listeners on $('#target') and its children.
When we call $('#target').remove() to delete it from DOM,will the listeners be removed?
If not,how to remove them together?
Depends on how you add the listeners. If you do
$("#target").click(function() { doSomething(); });
Then remove()
will also delete the listener. However, if you do:
$("#target").live("click", function() { doSomething(); });
The listener will not be removed. What you've done here is to create a live HTML collection, and if you at a later point add a new element with id of "target", it will get this listenere added to it.
Yes, the directly bound event handlers and the internally cached data will be removed.
From Manipulation/remove:
"Note that this function starting with 1.2.2 will also remove all event handlers and internally cached data."