How to remove an element from the DOM with vanilla JS

The Node.remove() method lets you remove an element from the DOM. Call it on the element you want to remove.
For example, let’s say you had a heading and paragraph, like this.
<h1>Hello, world!</h1> <p>How are you today?</p> To remove the h1 element, you would do this.
let h1 = document.querySelector(‘h1’); h1.remove(); Here’s a demo.


This content originally appeared on Go Make Things and was authored by Go Make Things

The Node.remove() method lets you remove an element from the DOM. Call it on the element you want to remove.

For example, let’s say you had a heading and paragraph, like this.

<h1>Hello, world!</h1>
<p>How are you today?</p>

To remove the h1 element, you would do this.

let h1 = document.querySelector('h1');
h1.remove();

Here’s a demo.


This content originally appeared on Go Make Things and was authored by Go Make Things


Print Share Comment Cite Upload Translate Updates
APA

Go Make Things | Sciencx (2021-03-25T14:30:00+00:00) How to remove an element from the DOM with vanilla JS. Retrieved from https://www.scien.cx/2021/03/25/how-to-remove-an-element-from-the-dom-with-vanilla-js/

MLA
" » How to remove an element from the DOM with vanilla JS." Go Make Things | Sciencx - Thursday March 25, 2021, https://www.scien.cx/2021/03/25/how-to-remove-an-element-from-the-dom-with-vanilla-js/
HARVARD
Go Make Things | Sciencx Thursday March 25, 2021 » How to remove an element from the DOM with vanilla JS., viewed ,<https://www.scien.cx/2021/03/25/how-to-remove-an-element-from-the-dom-with-vanilla-js/>
VANCOUVER
Go Make Things | Sciencx - » How to remove an element from the DOM with vanilla JS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/25/how-to-remove-an-element-from-the-dom-with-vanilla-js/
CHICAGO
" » How to remove an element from the DOM with vanilla JS." Go Make Things | Sciencx - Accessed . https://www.scien.cx/2021/03/25/how-to-remove-an-element-from-the-dom-with-vanilla-js/
IEEE
" » How to remove an element from the DOM with vanilla JS." Go Make Things | Sciencx [Online]. Available: https://www.scien.cx/2021/03/25/how-to-remove-an-element-from-the-dom-with-vanilla-js/. [Accessed: ]
rf:citation
» How to remove an element from the DOM with vanilla JS | Go Make Things | Sciencx | https://www.scien.cx/2021/03/25/how-to-remove-an-element-from-the-dom-with-vanilla-js/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.