Javascript examples for DOM:Event
Query element when DOM content is loaded via event handler for DOMContentLoaded
<html> <head> <script> document.addEventListener("DOMContentLoaded", function(event) { document.querySelector('#image1').addEventListener("click",myFunction); function myFunction(){/*from ww w.ja va 2s . co m*/ console.log("on click"); } }); </script> </head> <body> <img src="http://www.java2s.com/style/download.png" id="image1"> </body> </html>