jQuery Tutorial Tutorials - jQuery .detach() method

jQuery .detach() method

The .detach() method in jQuery is used to remove all matched elements from DOM. This method won't remove the jQuery data associated with the remove elements, like event hanlders,attached data.

jQuery .detach() method Syntax

.detach()

jQuery .detach() method Example

Detach all paragraphs from the DOM.
HTML

<div class="container">
    <p>Learn JavaScript</p>
    <p>Learn jQuery</p>
    Lautturi tutorial
</div>

jQuery

// we can store the remove elements and reinserted into the DOM at a later time.
var p = $("p").detach();

Result

<div class="container">
    Lautturi tutorial
</div>

Try now

Date:2019-08-21 12:25:59 From:www.Lautturi.com author:Lautturi