Easy Tutorial
❮ Css Scrolltop Sel Lt ❯

jQuery detach() Method

jQuery HTML/CSS Methods

Example

Remove all <p> elements:

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

Definition and Usage

The detach() method removes the selected elements, including all text and child nodes. It then preserves the data and events.

This method keeps a copy of the removed elements, allowing them to be reinserted later.

Tip: To remove elements and their data and events, use the remove() method instead.

Tip: To remove content from the selected elements only, use the empty() method.


Syntax


More Examples

Remove and Restore an Element

Difference Between detach() and remove()


jQuery HTML/CSS Methods

❮ Css Scrolltop Sel Lt ❯