Javascript examples for DOM Event:onclick
Use addEventListener to add event handler for click
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//from www . j a va 2 s .co m console.log("Connected"); var button = document.querySelector("button"); button.addEventListener("click", function() { console.log("Clicked"); document.body.style.background = "pink"; }); } </script> </head> <body> <button>Click me</button> </body> </html>