detach() method in jQuery

detach() in jQuery

This method removes the set of matched elements from the DOM.

It removes all the text and child nodes of the specified element.

It keeps all the jQuery data related to the removed elements, so that it can be reinserted into the DOM at a later time if needed.



Example 1 - detach

Try Yourself

Example 2 - detach and return

Try Yourself

Example 3 - set of matched elements to be removed

Try Yourself

Example 4 - detach with event

Try Yourself

Example 5 - Difference between remove() and detach()

Try Yourself