How to Remove DOM Element with JQuery
Remove DOM Element with JQuery:
Relation of JQuery
and DOM
JQuery is one of the most famous
JavaScript libraries online. There are so many articles in the web about it,
that I feel useless to describe it again. The good parts of that library are
the amazing way it handles the DOM. It is so good at that that I usually use it
with other JavaScript libraries.
Now I’m working on a task and
one of the main target of the completed task was the RAM usage of the code. It
just has about 100 dynamic DOM elements which on every event should be removed
form the tree and the RAM should be freed.
First step Unbind first:
The first simple sub-task was
to remove the event listeners. The problem is that if you don’t remove the
event listeners may result in memory leaks in JS. The way JQuery removes the
event listeners is with:
$(element).unbind()
That’s enough. Now the element
don’t have any event listeners attached to it.
second step Remove Elements:
Now you must just remove the
element from the tree with no fear of memory leaks, with just writing:
$(element).remove()
Comments
Post a Comment