Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Removing Elements</title> </head> <body> <div id="container"> <p id="paragraph">This is a paragraph.</p> <button id="remove-paragraph">Remove Paragraph</button> </div> <script> const container = document.getElementById('container'); const paragraph = document.getElementById('paragraph'); const removeParagraphButton = document.getElementById('remove-paragraph'); removeParagraphButton.addEventListener('click', () => { container.removeChild(paragraph); }); </script> </body> </html>