Javascript examples for DOM:Element addEventListener
Element addEventListener() Method - Execute a function when a user clicks on a <button> element:
<!DOCTYPE html> <html> <body> <button id="myBtn">Test</button> <p id="demo"> <script> document.getElementById("myBtn").addEventListener("click", myFunction); function myFunction() {/*from w w w .j a va2 s.c o m*/ document.getElementById("demo").innerHTML = "Hello World"; } </script> </body> </html>