Method: 1. Use "$("dom element")" to obtain the specified element object; 2. Use "element object.remove (element filter condition)" to delete the specified element, remove() The function of the method is to delete all matching elements from the DOM. Events bound to the elements, additional data, etc. will be deleted.
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
The remove() method removes all matching elements from the DOM.
This method does not delete the matching elements from the jQuery object, so these matching elements can be used again in the future. But in addition to the element itself being retained, other elements such as bound events, additional data, etc. will be removed.
remove() method removes the selected elements, including all text and child nodes.
This method will also remove the data and events of the selected element.
The syntax is:
$(selector).remove()
The example is as follows:
Delete the paragraph with hello class from the DOM
HTML code :
<p class="hello">Hello</p> how are <p>you?</p>
jQuery Code:
1. Use "$("dom element")" to obtain the specified element object
2. Use remove to delete it directly.
$("p").remove(".hello");
Output results:
how are <p>you?</p>
Recommended related video tutorials: jQuery video tutorial
The above is the detailed content of How to delete all matching elements from dom in jquery. For more information, please follow other related articles on the PHP Chinese website!