English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
$.remove(selector)
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 | Description |
---|---|
selector | Specify one or more elements to be removed (separated by spaces) (optional) |