How to delete all matching elements from dom in jquery

WBOY
Release: 2022-05-10 11:29:14
Original
3515 people have browsed it

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()
Copy after login

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>
Copy after login

jQuery Code:

1. Use "$("dom element")" to obtain the specified element object

2. Use remove to delete it directly.

$("p").remove(".hello");
Copy after login

Output results:

how are <p>you?</p>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template