jQuery Delete Element
- Previous Page jQuery Add
- Next Page jQuery CSS Class
With jQuery, it is easy to delete existing HTML elements.
Delete Element/Content
To delete elements and content, you can generally use the following two jQuery methods:
- remove() - Delete the selected element (and its child elements)
- empty() - Remove child elements from the selected element
jQuery remove() Method
The jQuery remove() method deletes the selected element and its child elements.
Example
$("#div1").remove();
jQuery empty() Method
The jQuery empty() method deletes the child elements of the selected elements.
Example
$("#div1").empty();
Filtering Deleted Elements
The jQuery remove() method also accepts a parameter that allows you to filter the elements to be deleted.
This parameter can be any jQuery selector syntax.
The following example deletes all <p> elements with class="italic":
Example
$("p").remove(".italic");
jQuery HTML Reference Manual
For the complete content of jQuery HTML methods, please visit the following reference manual:
- Previous Page jQuery Add
- Next Page jQuery CSS Class