Document addEventListener() Method - For browsers that don't support the addEventListener() method, use the attachEvent() method. - Javascript DOM

Javascript examples for DOM:Document addEventListener

Description

Document addEventListener() Method - For browsers that don't support the addEventListener() method, use the attachEvent() method.

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials