HTML and CSS Reference
In-Depth Information
Figure 15.42 After the mouse event is fired on the second paragraph.
15.9.3 Removing an EventListener
To remove an event handler, the W3C provides the removeEventListener() method. With
this function you can choose which event listeners to remove. The method takes three
arguments: the name of the event, the function that will handle the event, and the Bool-
ean flag, useCapture , which specifies the event flow: true for event capturing and false for
event bubbling, the default. Note: The keyword “on” is not used with the event type,
whereas with the Internet Explorer model it is required.
element.removeEventListener(eventType, function, useCapture);
element.addEventListener("mouseover", highlight, false);
element.removeEventListener("mouseover", highlight, false);
Note that you must specify the same useCapture value when removing a listener
exactly as you used it when adding the event listener. To remove the event handler, sim-
ply make the onclick method empty. The results is shown in Figure 15.43.
Another way to remove the event handler is to set its value to null as:
element.onclick = null;
Search WWH ::

Custom Search