jQuery .detach() Method

Last Updated Jul 21, 2015, 12:00:06 PM

jQuery .detach() Method

jQuery detach() method is used remove the selected HTMLelements from the DOM tree.


The jquery detach() method is same as jquery remove() method but the only difference is, detach method keeps the data of removed elements. In case,If you want to reinsert the removed elements back to the DOM, you can easily do that using detach() method since it keeps the those removed DOM element ids.


Note that, in the above HTML code we have two different texts in two p tags and one bold text in b tag

Using the below jquery detach() method, we can simply target those two p elements and toggle them by removing and adding back again


The above jQuery detach() method example will produce the following output

jQuery detach() method
Try It Now

jQuery DOM Reference

Other Advanced jQuery and DOM topics you might want to learn

jQuery Basic DOM Methods

jQuery DOM Removal

jQuery DOM Insertion Inside

jQuery DOM Insertion Outside

jQuery DOM Insertion Around

Sources and Credits

The content and methods in the tutorial has been referred and updated with jQuery API and The jQuery Foundation

Last Updated Jul 21, 2015, 12:00:06 PM