Document addEventListener() Method - Add different type of events to the document. - Javascript DOM

Javascript examples for DOM:Document addEventListener

Description

Document addEventListener() Method - Add different type of events to the document.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
document.addEventListener("mouseover", myFunction);
document.addEventListener("click", mySecondFunction);
document.addEventListener("mouseout", myThirdFunction);

function myFunction() {//from w w  w. j a  v a  2 s .c om
    document.getElementById("demo").innerHTML += "Moused over!<br>"
}

function mySecondFunction() {
    document.getElementById("demo").innerHTML += "Clicked!<br>"
}

function myThirdFunction() {
    document.getElementById("demo").innerHTML += "Moused out!<br>"
}
</script>

</body>
</html>

Related Tutorials