YouTip LogoYouTip

Met Element Removeeventlistener

# HTML DOM removeEventListener() Method [![Image 3: Element Object Reference](#) Element Object](#) ## Example Remove the "mousemove" event handler added by the addEventListener() method: // Add an event handler to the
element document.getElementById("myDIV").addEventListener("mousemove", myFunction); // Remove the event handler from the
element document.getElementById("myDIV").removeEventListener("mousemove", myFunction); [Try it Β»](#) * * * ## Definition and Usage The removeEventListener() method is used to remove an event handler that was added with the [addEventListener()](#) method. **Note:** To remove an event handler, the function specified in the addEventListener() method must be an external function, as shown in the example above (myFunction). Anonymous functions, like "document.removeEventListener("_event_", function(){ _myScript_ });", cannot remove the event. * * * ## Browser Support The numbers in the table specify the first browser version that fully supports the method. | Method | | | | | | | --- | --- | --- | --- | --- | --- | | removeEventListener() | 1.0 | 9.0 | 1.0 | 1.0 | 7.0 | **Note:** Internet Explorer 8 and earlier IE versions do not support the removeEventListener() method, and Opera 7.0 and earlier Opera versions do not either. However, for these browsers that do not support this function, you can use the **detachEvent()** method to remove an event handler added with the attachEvent() method (see "More Examples" for a cross-browser solution). * * * ## Syntax _element_.removeEventListener(_event_, _function_, _useCapture_) ## Parameter Values | Parameter | Description | | --- | --- | | _event_ | Required. The name of the event to remove. **Note:** Do not use the "on" prefix. For example, use "click" instead of "onclick". **Tip:** To see a list of all HTML DOM events, please look at our complete (#). | | _function_ | Required. The function to remove. | | _useCapture_ | Optional. A Boolean value that specifies the phase of the event handler to remove. Possible values: * true - Remove the event handler during the capture phase * false - Default. Remove the event handler during the bubbling phase **Note:** If you add an event handler twice, once in the capture phase and once in the bubbling phase, you must remove the event handler separately. | ## Technical Details | DOM Version: | DOM Level 2 events | | --- | | Return Value: | No return value | | Change History: | The useCapture parameter is optional in Firefox 6 and Opera 12.0. (It has always been optional in Chrome, IE, and Safari). | * * * ## More Examples ## Example If the browser does not support the removeEventListener() method, you can use the detachEvent() method as an alternative. This example demonstrates a cross-browser solution: var x = document.getElementById("myDIV"); if (x.removeEventListener) {// // All browsers except IE 8 and earlier IE versions x.remov
← Browsers Resolution HigherJs Htmldom Eventlistener β†’

YouTip © 2024-2026 | Home | Learn Technology, Build Dreams!

All content is for educational and learning purposes only.