JavaScript Code

How to remove paragraph using JavaScript?

Tutorials using JS

Remove paragraph using JavaScript

In this tutorial, you shall learn how to remove paragraph element from the document using JavaScript.


To remove a paragraph element from document using JavaScript, we can use remove() method on the element. Get the paragraph element, and call remove() method.


remove() method removes the calling element from the document.


In the HTML, we have a Click me button and paragraph. When user clicks on the Click me button, we get the paragraph element by id myPara and remove it from the document using remove().

<!DOCTYPE html>
<h1>JavaScript Tutorial</h1>
<button id="myBtn">Click me</button>
<p id="myPara">This is a paragraph. Welcome to JavaScript tutorials.</p>

document.getElementById("myBtn").addEventListener("click", function() {
    //get the paragraph element
    const myPara = document.getElementById("myPara");
    //remove the paragraph


Copyright @2022