Home  >  Article  >  Web Front-end  >  How to delete all matching elements from dom in jquery

How to delete all matching elements from dom in jquery

WBOY
WBOYOriginal
2022-05-10 11:29:143504browse

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.

How to delete all matching elements from dom in jquery

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How jquery removes all matching elements from the DOM

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn