Javascript Reference - HTML DOM removeEventListener() Method








The document.removeEventListener() method removes an event handler that has been added with the document.addEventListener() method.

Browser Support

removeEventListener Yes 9.0 Yes Yes Yes

Syntax

document.removeEventListener(event, function, useCapture) 

Parameter Values

Parameter Description
event Required. name of the event to remove.
function Required. Specifies the function to remove.
useCapture Optional.
  • true - Removes the event handler from the capturing phase
  • false- Default. Removes the event handler from the bubbling phase




Return Value

No return value

Example

The following code shows how to remove a "mousemove" event that has been attached with the addEventListener() method.


<!DOCTYPE html>
<html>
<body>
<button onclick="removeHandler()">test</button>
<p id="demo"></p>
<script>
document.addEventListener("mousemove", myFunction);
<!-- w  ww  . j  ava2 s . c om-->
function myFunction() {
    document.getElementById("demo").innerHTML = Math.random();
}

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

</body>
</html>

The code above is rendered as follows: