jQuery - Remove Elements


Using jQuery, you can easily delete existing HTML elements.


Remove Elements/Content

To get rid of things on a webpage, you can use two main methods in jQuery.

  • remove() - Removes the selected element (and its child elements)
  • empty() - Removes the child elements from the selected element

jQuery remove() Method

The jQuery remove() function deletes the chosen element or elements along with their children.


jQuery empty() Method

The jQuery method called empty() takes away the things inside the chosen element(s).


Filter the Elements to be Removed

The jQuery method remove() can accept one parameter. This parameter helps you choose which elements you want to delete.

The parameter can take on any of the jQuery selector formats.

In this example, we eliminate all <p> elements that have the class="test" attribute.

In this example, we delete all <p> elements that have both class="test" and class="demo":