Latest web development tutorials

jQuery detach () method

jQuery HTML / CSS Methods jQuery HTML / CSS Methods

Examples

Remove all the <p> element:

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

try it"

Definition and Usage

detach () method to remove the selected elements, including all text and child nodes. It will then retain the data and events.

This method will keep a copy of the removed elements, allowing them to be re-inserted later.

Tip: To remove the element and its data and events, use the remove () method instead.

Tip: If you need to remove content from the selected element, use empty () method.


grammar

$(selector).detach()


Examples

More examples

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

Different detach () and remove () between
Between different methods of presentation detach () and remove ().


jQuery HTML / CSS Methods jQuery HTML / CSS Methods