jQuery - Remove Elements
With jQuery, it is easy to remove existing HTML elements.
Remove elements/content
To remove elements and content, you can generally use the following two jQuery methods:
- remove() - removes the selected elements (and their children)
- empty() - removes the children of the selected elements
jQuery remove() method
The jQuery remove() method removes the selected elements and their children.
Example
$
(
"
#div1
"
)
.
remove
(
)
;
Try it »
jQuery empty() method
The jQuery empty() method removes the children of the selected elements.
Example
$
(
"
#div1
"
)
.
empty
(
)
;
Try it »
Filtering removed elements
The jQuery remove() method also accepts a parameter that lets you filter the elements to be removed.
This parameter can be any jQuery selector syntax.
The following example removes all elements with class="italic"
element:
Example
$
(
"
p
"
)
.
remove
(
"
.italic
"
)
;
Try it »