This post will discuss how to remove the given element and its descendants from DOM using JavaScript and jQuery.

1. Using jQuery

To remove the specified elements from the DOM, you can use jQuery’s .remove() method. The following example demonstrates its usage by removing the login form from the DOM with the click of the remove button.

jQuery


HTML



Edit in JSFiddle

2. Using JavaScript

In plain JavaScript, you can get the corresponding element using the getElementById() or querySelector() method and then call the native remove() method on it. Following is a simple example demonstrating usage of this method:

JS


HTML



Edit in JSFiddle

 
Another solution to remove the DOM element is to set the outerHTML attribute of the element to an empty string.

JS


HTML



Edit in JSFiddle

 
Another plausible way is to visit its parent and then remove the element from DOM using the removeChild() method.

JS


HTML



Edit in JSFiddle

That’s all about removing an element from DOM in JavaScript and jQuery.