Example

Remove all p elements:

$("button").click(function(){
  $("p").detach();
});

Try it yourself »

Definition and Usage

The detach() method removes the selected elements, including all text and child nodes.

This method keeps a copy of the removed elements, which allows them to be reinserted at a later time.

The detach() method also keeps the element's jQuery data, like event handlers.

Syntax

$(selector).detach()


Examples

Try it Yourself - Examples

Remove and restore an element
How to use the detach() method to remove and restore an element.

Move an element and keep its click event
How to use the detach() method to move an element, and keep the element's jQuery data.