Jquery method to remove elements: 1. Delete the selected element and its sub-elements through the jQuery remove() method. The syntax is "$("#div1").remove();"; 2. Through The jQuery empty() method deletes the child elements of the selected element. The syntax is "$("#div1").empty();".
The operating environment of this tutorial: Windows 10 system, jquery3.2.1 version, Dell G3 computer.
How to remove elements with jquery?
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() - Removes the selected element (and its child elements)
empty() - Removes the child element from the selected element
jQuery remove() method
jQuery remove() method removes the selected element and its child elements.
$("#div1").remove();
jQuery empty() method
jQuery empty() method deletes the child elements of the selected element.
$("#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
elements of class="italic":
$("p").remove(".italic");
Recommended learning: "jQuery Video Tutorial"
The above is the detailed content of How to remove elements with jquery. For more information, please follow other related articles on the PHP Chinese website!