jquery remove detach empty - what is the difference?

by Guna 2013-09-04 12:13:17

Jquery gives you 3 methods to remove element. These three methods do the same functionality ie. removing elements, but with minor changes between them.

.remove()

$('#id').remove(), will cleans up id and its child elments from DOM.

.empty()

$('#id').empty(), will remove all the nested elements of id from DOM. note: the element #id is still alive.

.detach()

var elem=$('#id').detach(), will remove id and its nested elements from DOM. But keeps its data and event handlers in variable if assigned.




725
like
0
dislike
0
mail
flag

You must LOGIN to add comments