Method to delete all elements under a node: 1. Use find() to obtain all subset elements under the node (including subsets of subsets), the syntax is "specify node object.find("*") "; 2. Use remove() to delete the obtained elements (including all text and sub-nodes), the syntax is "acquired element set.remove()".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
jquery method of deleting all elements under a node
Implementation idea:
Use find( ) method to obtain all subset elements (including subsets of subsets) under the node
Use the remove() method to delete all obtained subset elements
Implementation code:
div (父节点)ul (指定元素)
- li (子节点1) span (孙节点1)
- li (子节点2) span (孙节点2)
- li (子节点3) span (孙节点3)
Description:
find() method returns the selected element The descendant element of (descendants are children, grandchildren, great-grandchildren, and so on.).
The find() method traverses all paths down the DOM element's descendants to the last descendant ().
#The remove() method removes the selected elements, including all text and child nodes. This method also removes data and events from the selected element.
【Recommended learning:jQuery video tutorial,web front-end video】
The above is the detailed content of How to delete all elements under a node in jquery. For more information, please follow other related articles on the PHP Chinese website!