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
What is meant by a deep copy? : jQuery Mobile
How to disable/enable an element in jquery?
How to get the current offset of the first matched element, in pixels, relative to the document using ?
What is the use of val() method in jquery?
Which sign is used as a shortcut for jQuery?
What happen if you return false from a jQuery event handler?
What is event preventdefault () and event stoppropagation () in jquery?
Explain chaining in jquery? : jquery mobile
What are different type of selector in jQuery?
What is eq()? : jquery mobile
How to get the server response from an ajax request using jquery?
How to check data type of any variable in jquery? : jquery mobile
How can you use array with jquery?
What is cdn? Explain
Is jquery a library for client scripting or server scripting? : jquery mobile