Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Remove an Element from the DOM</title> </head> <body> <div id="main"> <h1 id="title">Hello World!</h1> <p id="hint">This is a simple paragraph.</p> </div> <button type="button" onclick="removeElement()">Remove Element</button> <script> function removeElement() { let parentElem = document.getElementById("main"); let childElem = document.getElementById("hint"); parentElem.removeChild(childElem); } </script> </body> </html>