jQuery remove() Method
Example
Remove all <p> elements:
$("button").click(function(){
$("p").remove();
});
Try it Yourself »
Definition and Usage
The remove() method removes the selected elements, including all text and child nodes.
This method also removes data and events of the selected elements.
Tip: To remove the elements without removing data and events, use the detach() method instead.
Tip: To remove only the content from the selected elements, use the empty() method.
Syntax
$(selector).remove(selector)
Parameter | Description |
---|---|
selector | Optional. Specifies one or more elements to be removed.
To remove multiple elements, separate them with a comma (,) |
Try it Yourself - Examples
Difference between detach() and remove()
Show the difference between the detach() and remove() methods.
Remove all <p> elements with class="test"
Using the optional parameter to filter the elements to be removed.
Remove all <p> elements with class="test" and "demo"
Using the optional parameter to filter multiple elements to be removed.