What is the difference between .empty(), .remove() and .detach() methods in jQuery?
Answer / 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 |
Whether we need to add jQuery file in both Master and Content page?
Explain .empty() vs .remove() vs .detach() in jquery
How JavaScript and jQuery are different?
Change the url for a hyperlink using jquery?
Why content injected into a page is not enhanced? : jquery mobile
How can you apply a style on an element using jQuery?
What is the use of .size() method in jquery?
What is difference between prop and attr?
How to get attributes of an element using jQuery?
How to load jQuery locally when CDN fails?
What are selectors in jquery mean ?
How to control page titles in jquery mobile? : jquery mobile