English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery remove() method

jQuery HTML/CSS Methods

The remove() method deletes the selected element and its child elements from the DOM.

This method also removes the data and events of the selected element.

To remove the element without removing data and events (so that they can be re-added later), usedetach()Method.

To remove content from the selected element only, useempty()Method.

Syntax:

$.remove(selector)

Example

Remove all paragraphs from the DOM:

$("button").click(function(){
  $("p").remove();
});
Test See‹/›

Remove all paragraphs containing 'Hello' from the DOM:

$("button").click(function(){
  $("p").remove(":contains('Hello')");
});
Test See‹/›

The above example can also be written as:

$("button").click(function(){
  $("p:contains('Hello')").remove();
});
Test See‹/›

Parameter Value

ParameterDescription
selectorSpecify one or more elements to be removed (separated by spaces) (optional)

jQuery HTML/CSS Methods