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 |
How do you select an item using css class or id and get the value by use of jquery.
Explain some benefits of jquery knockout?
What are the two types of CDNs?
Explain .bind() vs .live() vs .delegate() vs .on()
What is meant by the term ‘theming’ in jquery mobile? : jQuery Mobile
How to load a page using jquery mobile? : jquery mobile
Explain the types of selectors in jquery?
Tell me does jquery 2.0 supports ie? : jquery mobile
What is difference between .setinterval() and .delay() ?
How to use jquery library in our asp.net project?
What is event preventdefault () and event stoppropagation () in jquery?
What is event.stoppropagation? : jquery mobile