IMG-LOGO
Home Course Remove Elements in jquery

Remove Elements in jquery

by MH RISHAD - 04 May 2019
IMG

There are mainly two jQuery methods:

remove() - Removes the selected element (and its child elements) Also can be delete

empty() - Removes the child elements from the element, Which are selected

What is remove() Method

The jQuery remove() method removes the selected element(s) and also its child elements.

Example

$("#div1").remove();

What is empty() Method

The jQuery empty() method removes the child elements of the selected element(s).

Example

$("#div1").empty();

Filter the Elements to be Removed

The remove() method also accepts one parameter, which allows you to filter the elements to be removed.

The parameter can be any of the selector syntaxes.

Following example removes all <p> elements with class="test": 

 

Example

$("p").remove(".test");

This example removes all <p> elements with class="test" or class="test2": 

Example

$("p").remove(".test, . test2");
Share:

Leave a Comment

Required fields are marked *