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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -