What is the difference between .empty(), .remove() and .detach() methods in jQuery?



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

Post New Answer

More jQuery Interview Questions

Tell me how to disable jquery animation? : jquery mobile

0 Answers  


Tell me which command will give a version of jquery?

0 Answers  


Can you include multiple version of jQuery? If yes, then how they are executed?

1 Answers  


How can we apply css in odd childs of parent node using jquery library?

0 Answers  


What the use of $ symbol in jquery.

0 Answers  






What is jquery selectors?

0 Answers  


When can jquery be used?

0 Answers  


How do I pull a native DOM element from a jQuery object?

0 Answers   MCN Solutions,


What are source maps in jQuery?

1 Answers  


How to include jQuery in ASP.Net project?

0 Answers  


How to check jQuery version?

0 Answers  


Can you call C# code-behind method using jQuery? If yes,then how?

1 Answers  


Categories