Document removeEventListener() Method - Javascript DOM

Javascript examples for DOM:Document removeEventListener

Description

The document.removeEventListener() method removes an event handler attached with the document.addEventListener() method.

Parameter Values

Parameter Description
event Required. A String name of the event to remove.
function Required. Specifies the function to remove.
useCapture Optional.

useCapture value:

  • true - Removes the event handler from the capturing phase
  • false- Default. Removes the event handler from the bubbling phase

If the event handler was attached twice, one with capturing and one bubbling, each must be removed separately.

Return Value:

No return value

The following code shows how to Remove a "mousemove" event that has been attached with the 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  ww  w. ja v  a  2s . com
    document.getElementById("demo").innerHTML = Math.random();
}

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

</body>
</html>

Related Tutorials