<!DOCTYPE html>
<html>
<style>
#myDIV {
background-color: coral;
padding: 16px;
}
</style>
<body>
<h1>The Element Object</h1>
<h2>The removeEventListener() Method</h2>
<div id="myDIV">This orange element has an onmousemove event handler that displays a random number when you move the mouse inside.
<p>Click "Remove" to remove the event handler.</p>
<button onclick="removeHandler()">Remove</button>
</div>
<p id="demo"></p>
<script>
const myDiv = document.getElementById("myDIV");
myDiv.addEventListener("mousemove", myFunction);
function removeHandler() {
myDiv.removeEventListener("mousemove", myFunction);
}
function myFunction() {
document.getElementById("demo").innerHTML = Math.random();
}
</script>
</body>
</html>