Introduction to jQuery
JQuery Syntax
JQuery Effects
JQuery HTML
JQuery Traversing
In jQuery, you can easily remove elements from the DOM using several methods.
Method |
Description |
---|---|
.remove() |
Removes the selected element(s) from the DOM completely. |
.empty() |
Removes all child elements from the selected element(s) but keeps the element itself. |
The .remove()
method completely removes the selected element(s) and their associated data, events, and content from the DOM.
Try it yourself
The .empty()
method removes all child elements inside the selected element but keeps the selected element itself.
Try it yourself
In jQuery, you can filter elements before removing them using selectors or functions inside the .remove()
method. This allows you to remove only specific elements from a group.
The following example removes all <p>
elements with class="remove"
:
Try it yourself
This example removes all <p>
elements with class="removeMe"
and class="removeMeAlso"
:
Try it yourself