Home>Article>Web Front-end> How to use detach removal in jquery
In jquery, the detach method can be used to remove a selected element and remove all text and child nodes of the element, but the data and events will be retained and allowed to be reinserted later. The syntax is "$(selector) .detach()"; if you only need to remove content from the selected element, use the empty() method.
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
detach() method to remove selected elements, including all text and child nodes. It then persists the data and events.
This method keeps a copy of the removed elements, allowing them to be reinserted later.
Tip: If you need to remove an element and its data and events, use the remove() method instead.
Tip: If you only want to remove content from the selected elements, use the empty() method.
Grammar
$(selector).detach()
The example is as follows:
123 这是一个段落。
这是另一个段落。
Output result:
Related video tutorial recommendations:jQuery video tutorial
The above is the detailed content of How to use detach removal in jquery. For more information, please follow other related articles on the PHP Chinese website!