How jquery deletes all elements under a node
This article mainly explains "how jquery deletes all the elements under the node". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "jquery how to delete all the elements under the node".
Jq delete all elements under the node method: 1, use find () to get all under the node (including a subset of the subset) subset elements, syntax "specify node object .find (" * ")", will return a collection of elements; 2, use remove () to delete all elements in the set of elements, syntax "element collection .remove ()".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
The method of deleting all elements under a node by jquery
Realize the idea:
Use the find () method to get all subset elements (including subsets of subsets) under this node
Use the remove () method to delete all acquired subset elements
Implementation code:
.div, div * {display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px } ul * {color:red; border:2px solid red } $(document) .ready (function () {$("button") .on ("click", function () {$("ul") .find ("*") .remove () );}) Div (parent node) ul (specified element) li (child node 1) span (grandnode 1) Li (Child Node 2) span (grandNode 2) li (Child Node 3) span (grandNode 3) Delete all elements under the ul node
Thank you for reading, the above is the content of "how jquery deletes all elements under the node". After the study of this article, I believe you have a deeper understanding of how jquery deletes all elements under the node. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!