Latest web development tutorials

HTML DOM removeEventListener () method

Document Object Reference Document Object

Examples

Remove the addEventListener () method to add the "mousemove" event:

// Add event handlers in the document
document.addEventListener ( "mousemove", myFunction);

// Remove the document event handler
document.removeEventListener ( "mousemove", myFunction);

try it"

Definitions and use

document.removeEventListener () method is used to remove the document.addEventListener () method to add event handlers.

Note: If you want to remove the event handler, addEventListener () function implementation must use an external function, as the example shown (myFunction).

Anonymous function, similar to "document.removeEventListener (" event ", function () {myScript});" This event can not be removed.

Tip: Use element .addEventListener () and element .removeEventListener () method to add or remove the specified element event handlers.


Browser Support

Figures in the table represent the first browser to support the method version number.

method
removeEventListener () 1.0 9.0 1.0 1.0 7.0

Note: Internet Explorer 8 and earlier versions do not support IE removeEventListener () method, Opera 7.0 and earlier versions do not support Opera. However, they do not support the function of the browser, you can use detachEvent () method to remove the attachEvent () method to add an event handler (see "More examples" for cross-browser solution).


grammar

document.removeEventListener (event, function, useCapture)

Parameter Value

parameter description
event have to. To remove the name of the event.

Note: Do not use the "on" prefix. For example, use "click", instead of "onclick".

Tip: All HTML DOM events, you can see our complete HTML DOM Event Object Reference .
function have to. Specify the function to be removed.
useCapture Optional. Boolean value that specifies remove the event handler stage.

Possible values:
  • true - event handler is removed during the capture phase
  • false- default. Remove the event handler for the bubbling phase
Note: If you add an event handler twice, once during the capture phase, once in the bubbling phase, you must remove the event.

technical details

DOM version: DOM Level 2 events
return value: No return value
Records: In Firefox 6 and Opera 12.0 in useCapture parameter is optional. (In Chrome, IE, and Safari has always been optional).


More examples

Examples

If your browser does not support the removeEventListener () method, you can use detachEvent () methods.

This example demonstrates the cross-browser solution:

if (document.removeEventListener) {// all browsers except IE 8 and earlier versions of IE
document.removeEventListener ( "mousemove", myFunction);
} Else if (document.detachEvent) {// IE 8 and earlier versions of IE
document.detachEvent ( "onmousemove", myFunction);
}

try it"


related articles

JavaScript tutorial: the HTML the DOM EventListener A

JavaScript Reference Manual: Element .removeEventListener ()


Document Object Reference Document Object