Document removeEventListener() Method - Javascript DOM

Javascript examples for DOM:Document removeEventListener


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>

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

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

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);


Related Tutorials