Remove element by id in JavaScript?

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

To remove element by id, you can use remove().


Following is the code −

<!DOCTYPE html>
<html lang="en">
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="//">
<script src=""></script>
<script src=""></script>
   <h1 id="demo">Hello</h1>
   <p id="demo1">This is my paragraph</p>

To run the above program, save the file name anyName.html(index.html). Right click on the file and select the option “Open with live server” in VS Code editor.


This will produce the following output −

Updated on 27-Oct-2020 09:42:36