What is the difference between .empty(), .remove() and .detach() methods in jQuery?
Answer Posted / chaitanya
All these methods .empty(), .remove() and .detach() are used for removing elements from DOM but they all are different.
.empty(): This method removes all the child element of the matched element where remove() method removes set of matched elements from DOM.
.remove(): Use .remove() when you want to remove the element itself, as well as everything inside it. In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed.
.detach(): This method is the same as .remove(), except that .detach() keeps all jQuery data associated with the removed elements. This method is useful when removed elements are to be reinserted into the DOM at a later time.
Find out more here
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Differentiate among .empty() vs .remove() vs .detach() in jquery.
What does the jQuery migrate function do?
What is the purpose of jquery?
How to call a method inside code-behind using jquery?
How to disable/enable an element with jQuery?
Explain the basic need to start with jquery? : jquery mobile
Why use jQuery filter() Methods?
Can you give me a brief history of your programming days? Where did it all start?
What is the use of val() method in jquery?
How can you get the type of arguments passed to a function?
Tell me what is the use of .size() method in jquery?
Define bind() and unbind elements in jQuery?
Tell me do I need to add the jquery file both at the master page and content page as well?
Why are not some scripts and styles loading? : jquery mobile
What is the difference between settimeout() and setinterval() methods?