jQuery remove() Method
jQuery remove() method removes the selected elements as well as everything inside it.
Use the empty() method to remove only the content from the selected elements.
Syntax
Here is a syntax for the remove() method
$(selector).remove( selector );
Parameter | Type | Description |
---|---|---|
selector | Selector | Optional. A selector expression that filter the matched elements to be removed. |
Example
Here, in this example remove() method call on selected elements when click on button.
<!DOCTYPE html>
<html>
<head>
<title>jQuery remove() method</title>
<script src="jquery-latest.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("div").remove();
});
});
</script>
</head>
<body>
<div>
<p>First paragraph start here...</p>
</div>
<button>Click here to call remove() method</button>
</body>
</html>