jquery - Javascript: should I remove an event handler when removing the related HTML? -
this question has answer here:
i have following html on page:
<div class="component"> <a href="#" class="delete">delete</a> </div>
and have following script @ page load:
$(document).ready(function(){ $('a.delete').on('click', function() { .... }); });
this page has other javascript code manipulates page , removes via:
$('.component').remove();
my question: need remove (unbind) event handler before removing html? if not, there memory leak or other impact?
thanks , regards!
because you're using jquery, don't need worry it.
similar
.empty()
,.remove()
method takes elements out of dom. use.remove()
when want remove element itself, inside it. in addition elements themselves, all bound events , jquery data associated elements removed. remove elements without removing data , events, use.detach()
instead.
http://api.jquery.com/remove/ (emphasis added)
Comments
Post a Comment