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
How to get the direct parent of an element using ?
How can jquery library be added to pages?
Tell me which command will give a version of jquery?
How do you install/use jquery in a project. What is the minimum setup needed to start using jquery.
How to increase cursor size in html body using jquery?
Is jquery a framework?
What is the use of delay() method in JQuery?
Explain the difference between jquery's ready and holdready?
How to redirect to another page using jquery?
Tell me do I need to add the jquery file both at the master page and content page as well?
Why do we need to go for JQuery?
How to check/uncheck an input in jquery?
Is window.onload is different from document.ready()?
What is the difference between jquery's ready and holdready?
What is $('div')? : jquery mobile