Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>getElementById Example</title> </head> <body> <div id="example">Click the button to change me!</div> <button onclick="changeContent()">Change Content</button> <script> function changeContent() { const element = document.getElementById('example'); element.textContent = "You clicked the button!"; } </script> </body> </html>