Latest web development tutorials

HTML DOM removeEventListener () method

Elements Object Reference Element object

Examples

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

// Add an event handler to the <div> element
. Document.getElementById ( "myDIV") addEventListener ( "mousemove", myFunction);

// Remove the <div> element event handlers
. Document.getElementById ( "myDIV") removeEventListener ( "mousemove", myFunction);

try it"

Definition and Usage

removeEventListener () method is used to remove the 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.


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

element .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 - remove an event handler during the capture phase
  • false- default. Remove an 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:

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

try it"


Related Pages

JavaScript tutorial: the HTML the DOM EventListener A

JavaScript Reference Manual: document.removeEventListener ()


Elements Object Reference Element object