The following example may use the following HTML code:
1. remove() method:
Function: Remove all matching elements from the DOM. The passed parameters are used to filter elements based on jQuery expressions.
For example, to delete the second
When a node is deleted using the remove() method, all descendant nodes contained in the node will be deleted at the same time. The return value of this method is a reference to the deleted node, so the elements can be used again later. The following jQuery code shows that after the element is deleted using the remove() method, it can still be used.
You can directly use the features of the appendTo() method to simplify the above code:
In addition, the remove() method can also selectively delete elements by passing parameters:
2. detach() method:
Detach(), like remove(), also removes all matching elements from the DOM. However, it should be noted that this method will not remove the matching elements from the jQuery object, thus making it possible to reuse these matching elements in the future. Different from remove(), all bound events, attachment data, etc. will be retained.
Through the following example, you can know the difference between it and the remove() method:
3. empty() method
Strictly speaking, the empty() method does not delete the node, but clears the node. It can clear all descendant nodes in the element.
The result after running is:
When the code is run, the content of the second
The above is all the content described in this article, I hope you all like it.