Home  >  Article  >  Web Front-end  >  How to delete elements in jquery

How to delete elements in jquery

藏色散人
藏色散人Original
2020-11-18 14:44:293041browse

Jquery method to delete elements: 1. Use the remove method to delete the selected element and its sub-elements. Its syntax is such as "$("#div1").remove();"; 2. Use the empty method to delete The child elements of the selected element, its syntax is such as "$("#div1").empty();".

How to delete elements in jquery

Recommended: "jquery video tutorial"

jQuery - Delete elements

With jQuery, you can easily delete existing HTML elements.

Delete elements/content

If you need to delete elements and content, you can generally use the following two jQuery methods:

remove() - delete the selected element (and its children) Element)

empty() - Removes child elements from the selected element

jQuery remove() method

jQuery remove() method removes the element being Select an element and its subelements.

Example

$("#div1").remove();

jQuery empty() method

jQuery empty() method deletes the child elements of the selected element.

Example

$("#div1").empty();

Filter deleted elements

The jQuery remove() method also accepts a parameter, allowing you to filter deleted elements.

This parameter can be any jQuery selector syntax.

The following example deletes all e388a4556c0f65e1904146cc1a846bee elements of class="italic":

Example

$("p").remove(".italic");

The above is the detailed content of How to delete elements 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