Javascript examples for DOM:Document removeEventListener
The document.removeEventListener() method removes an event handler attached with the document.addEventListener() method.
Parameter | Description |
---|---|
event | Required. A String name of the event to remove. |
function | Required. Specifies the function to remove. |
useCapture | Optional. |
useCapture value:
If the event handler was attached twice, one with capturing and one bubbling, each must be removed separately.
No return value
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); 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>