Home > Web Front-end > JS Tutorial > body text

How to delete elements in jquery

藏色散人
Release: 2020-11-18 14:44:29
Original
3210 people have browsed it

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

jQuery empty() method

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

Example

$("#div1").empty();
Copy after login

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

elements of class="italic":

Example

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

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!

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