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 |
Is jQuery a W3C standard?
How to increase cursor size in html body using jquery?
How can images be made to appear scrolling one over another?
Explain the each() function?
Can you please explain the difference between body onload() and document.ready() function? : jquery mobile
Explain the use of the .pushstack() method.
Mac, windows or linux? Why do you love this platform while using jquery?
How to create, read and delete cookies with jquery?
Is it too early to discuss jquery ui 1.8?
How to validate email using jquery?
Can we have multiple document.ready() function on the same page? : jquery mobile
What are the advantages of using cdn?