Reputation: 3825
If I register an jquery event handler on a DIV - what happens after the removal of the DIV? If I do this regularly (single page app) - will I run into memory leaks?
HTML:
<div id="elm12345"></div>
JS:
$('#elm12345').on(...);
...
$('#elm12345').remove();
Do I have to remove the event handler manually?
Upvotes: 0
Views: 97
Reputation: 12508
Per the jQuery documentation for .remove()
:
Similar to
.empty()
, the.remove()
method takes elements out of the DOM. Use .remove() when you want to remove the element itself, as well as everything inside it. In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed. To remove the elements without removing data and events, use .detach() instead.
Reference: .remove()
I've highlighted the part of the passage that answers your question. You can find this passage on the linked reference page, first paragraph.
Upvotes: 2