Document addEventListener() Method - Use removeEventListener() to remove an event handler attached by addEventListener() method: - Javascript DOM

Javascript examples for DOM:Document addEventListener

Description

Document addEventListener() Method - Use removeEventListener() to remove an event handler attached by addEventListener() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="removeHandler()">Test</button>

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

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

function myFunction() {//from  w ww .  j  a  v  a  2s .c o  m
    document.getElementById("demo").innerHTML = Math.random();
}

function removeHandler() {
    document.removeEventListener("mousemove", myFunction);
}
</script>

</body>
</html>

Related Tutorials