English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The element.removeEventListener() method will remove the event handler that has been associated with the element.addEventListener() method.
Note:To remove the event handler, the function specified by the addEventListener() method must be an external 'named' function, as shown in the following example (myFunc).
Anonymous function, such as " element .removeEventListener(" event ”,function(){ statement );' does not work.
Usagedocument.addEventListener()This method attaches the event handler to the document.
Usagedocument.removeEventListener()This method removes the event handler from the document.
element.removeEventListener(event, listener, useCapture)
var box = document.getElementById("para"); //Attach the event handler to the P element with id = 'para '. box.addEventListener("mousemove", myFunc); // Remove the event handler from the P element with id = 'para'. box.removeEventListener("mousemove", myFunc);Test and see‹/›
The numbers in the table specify the first browser version that fully supports the removeEventListener() method:
Method | |||||
removeEventListener() | 1 | 1 | 7 | 1.0 | 9 |
Parameters | Description |
---|---|
event | (Required) The name of the JavaScript event to be deleted. Do not use the 'on' prefix when using an event, for example, use 'click' instead of 'onclick' or 'mousedown' instead of 'onmousedown'. For a list of all HTML DOM events, please refer to our completeHTML DOM Event Object Reference. |
listener | (Required) The name of the JavaScript function to be removed. |
useCapture | (Optional) Boolean value, specifying whether to remove the event in the capture phase or the bubble phase. The default is false. Possible Values:
Note:If the event handler is attached twice, once for capture and once for bubble, it must be removed separately. You can find more information in ourIn the JavaScript event propagation tutorialRead more about event propagation |
Return Value: | None |
---|---|
DOM Version: | DOM 2Level |
JavaScript Tutorial:Event Listener
JavaScript Tutorial:Event Propagation
HTML DOM Reference:element .addEventListener()
HTML DOM Reference:document.addEventListener()
HTML DOM Reference:document.removeEventListener()