Javascript examples for DOM:Document addEventListener
Document addEventListener() Method - For browsers that don't support the addEventListener() method, use the attachEvent() method.
<!DOCTYPE html> <html> <body> <script> if (document.addEventListener) {//from w ww . ja v a 2 s.c o m document.addEventListener("click", myFunction); } else if (document.attachEvent) { document.attachEvent("onclick", myFunction); } function myFunction() { console.log("Hello World!"); } </script> </body> </html>