Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery detach() method

jQuery detach() method

jQuery HTML/CSS methods jQuery HTML/CSS methods

Example

Remove all the

element:

$

(

"

button

"

)

.

click

(

function

(

)

{

$

(

"

p

"

)

.

detach

(

)

;

}

)

;

Try it »


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 the elements along with their data and events, use remove() method instead.

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


Syntax

$(

selector

).detach()


More examples

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

The difference between detach() and remove()
Demonstrates the difference between the detach() and remove() methods.


jQuery HTML/CSS methods jQuery HTML/CSS methods