Skip to content

Instantly share code, notes, and snippets.

@Microsofttechies
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save Microsofttechies/a322d0fa63c47bba9563 to your computer and use it in GitHub Desktop.

Select an option

Save Microsofttechies/a322d0fa63c47bba9563 to your computer and use it in GitHub Desktop.
window.addEventListener
<!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