YouTip LogoYouTip

Met Document Removeeventlistener

# HTML DOM removeEventListener() Method [![Image 3: Document Object Reference](#) Document Object](#) ## Example Remove the "mousemove" event added by the addEventListener() method: // Add event handler in the document document.addEventListener("mousemove", myFunction); // Remove event handler in the document document.removeEventListener("mousemove", myFunction); [Try it Yourself Β»](#) * * * ## Definition and Usage The document.removeEventListener() method is used to remove an event handler that was added with the [document.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 be removed. **Tip:** Use the [_element_.addEventListener()](#) and [_element_.removeEventListener()](#) methods to add or remove event handlers for a specific element. * * * ## 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 document.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:** All HTML DOM events can be found in 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 - The event handler is removed during the capture phase * false- Default. The event handler is removed during the bubbling phase **Note:** If you add the same event handler twice, once in the capture phase and once in the bubbling phase, you must remove the event 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 a fallback.
← Met Element AddeventlistenerMet Document Addeventlistener β†’