The .remove()
method removes all matched elements from the DOM. Use .remove()
when you want to remove the element itself, as well as everything inside it (its child elements). In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed.
Example
<head>
<meta charset="utf-8">
<title>remove demo</title>
<style>
p {
background: yellow;
margin: 6px 0;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<p>Hello how are you?</p>
Hello how are you?
<p>Hello how are you?</p>
<button>Remove Element</button>
<script>
$( "button" ).click(function() {
$( "p" ).remove();
});
</script>
</body>
Preview
After Click on Remove Element Button