Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery remove elements

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:


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 »