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 the between $(this) and 'this' in jquery?
How to get the style property of an element using ?
What does $("P") will select?
What are the various ajax functions?
What is the advantage of using minimized version of jQuery?
Why is not dom ready working for jquery mobile? : jquery mobile
How can you select all elements in a page using jquery?
Tell me does jquery 2.0 supports ie? : jquery mobile
What is the use of jQuery filter?
How we can modify the css class in jquery?
Tell me what is the use of .size() method in jquery?
What were the biggest challenges of getting the 1.7 release out there?
What are some of the ways to provide effects? : jQuery Mobile
How do I pull a native DOM element from a jQuery object?
Explain the difference between jquery-x.x.x.js and jquery.x.x.x min.js?