Document addEventListener() Method - Assign "named" function to addEventListener() method - Javascript DOM

Javascript examples for DOM:Document addEventListener

Introduction

Use addEventListener() to execute a function when a user clicks anywhere in the document.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="demo">

<script>
document.addEventListener("click", myFunction);

function myFunction() {//from   w w  w  . j  a  va2s .  c o m
    document.getElementById("demo").innerHTML = "Hello World";
}
</script>

</body>
</html>

Related Tutorials