Last active
August 29, 2015 14:06
-
-
Save Microsofttechies/a322d0fa63c47bba9563 to your computer and use it in GitHub Desktop.
window.addEventListener
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <body> | |
| <p>Click anywhere in the document.</p> | |
| <p id="demo"></p> | |
| <p id="demo1"></p> | |
| <p id="demo2"></p> | |
| <script> | |
| function callOnload() { | |
| document.getElementById("demo2").innerHTML = "I am from Onload"; | |
| } | |
| //On page load | |
| if (window.addEventListener) { | |
| window.addEventListener('load', callOnload, false); //W3C | |
| } | |
| else { | |
| window.attachEvent('onload', callOnload); //IE | |
| } | |
| //On click of page | |
| document.addEventListener("click", function () { | |
| document.getElementById("demo").innerHTML = "Hello World!"; | |
| }); | |
| //On click of page | |
| window.addEventListener("click", myFunction, false); | |
| function myFunction() { | |
| document.getElementById("demo1").innerHTML = "Welcome ..."; | |
| } | |
| </script> | |
| </body> | |
| </html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment