Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In jQuery if you remove an element will any events on it be removed?

For example if I have a link with the following event bound to it:

$("a.d").bind("click", this, onDelete);

And later do:

$("a.d").remove();

Is that fine? Or does it cause a memory leak and I need to call unbind 1st?

Thanks for any help.

like image 506
user169867 Avatar asked Mar 01 '23 05:03

user169867


1 Answers

From jQuery docs for remove()

Removes all matched elements from the DOM. This does NOT remove them from the jQuery object, allowing you to use the matched elements further. Note that this function starting with 1.2.2 will also remove all event handlers and internally cached data.

like image 72
code_burgar Avatar answered May 01 '23 20:05

code_burgar