X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

jQuery detach() Method

jQuery HTML/CSS Methods jQuery HTML/CSS Methods

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. However, it keeps data and events.

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

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

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


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.

Difference between detach() and remove()
Show the difference between the detach() and remove() methods.


jQuery HTML/CSS Methods jQuery HTML/CSS Methods


Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook