Home >Web Front-end >JS Tutorial >How to delete elements in jquery
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();".
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!