Name
Element.attachEvent( ): register an event handler — IE 4:
Synopsis
void attachEvent(Stringtype, Functionlistener);
Arguments
-
type The type of event for which the event listener is to be invoked, with a leading “on” prefix. For example, “onload”, “onclick”, or “onmousedown”.
-
listener The event listener function that is invoked when an event of the specified type is dispatched to this element. This function is not passed any arguments but can obtain the Event object from the
eventproperty of the Window object.
Description
This method is an IE-specific event registration method. It
serves the same purpose as the standard addEventListener( ) method (which IE does
not support) but is different from that function in several
important ways:
Since the IE event model does not support event capturing,
attachEvent( )anddetachEvent( )expect only two arguments: the event type and the handler function.The event-handler names passed to the IE methods should include the “on” prefix. For example, use “onclick” with
attachEvent( )instead of “click” foraddEventListener( ).Functions registered with
attachEvent( )are invoked with no Event object argument. Instead, they must read theeventproperty of the Window object.Functions registered with
attachEvent( )are invoked as global functions, rather than as methods of the document element on which the event occurred. That is, when an event handler registered withattachEvent( )executes, thethiskeyword refers to the Window object, not to the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access