Exercise:
When the button is clicked, trigger myFunction() with an event.
Hint
Hint: Add an onclick event.
Edit This Code:
See Result »
<!DOCTYPE html> <html> <body> <button>Click Me</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = "Hello World"; } </script> </body> </html>
Result:
Show Answer
Correct Code:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Click Me</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = "Hello World"; } </script> </body> </html>
Correct Result:
Hide Answer
Privacy Policy