The Cross-Browser Event Model: Elements that Initiate Events - Doc JavaScript | WebReference

The Cross-Browser Event Model: Elements that Initiate Events - Doc JavaScript


Elements that Initiate Events

With Internet Explorer 4.0x, every HTML element on the page can be the source for a full set of mouse and keyboard events. For example, the following elements support the onmouseup event handler:

A, ADDRESS, APPLET, AREA, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, DD, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET FONT, FORM, H1, H2, H3, H4, H5, H6, HR, I, IMG, INPUT, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, OBJECT, OL, OPTION, P, PLAINTEXT, PRE, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP, document

Although Navigator 4.0x greatly expanded its set of elements that generate events, the selection is still much more limited. Not all elements can be the source of a mouse or keyboard event. For comparison, here's a list of the elements that support the onmouseup event handler in Navigator 4.0x:

A, AREA, button (a sub-element of INPUT), IMG, document

Needless to say, there are only several elements that accept the onmouseup event handler in Navigator 4.0x. There is obviously no way to specify an event handler for an element that doesn't support it. Since Internet Explorer 4.0x normally features much more elements that support a given event handler, you should only use those that are also supported by Navigator 4.0x when writing a cross-browser script. In any case, if you add an event handler to an element that doesn't support that type of event handler, it has no effect. Regardless of whether you specify the event handler as a property or as an HTML attribute, the browser does not generate an error (because HTML never causes explicit errors, and adding a new property to an existing object is a legal JavaScript operation). For example, Navigator 4.0x ignores the following event handler specification, whereas Internet Explorer 4.0x supports it:

<P onClick="alert('This only works with Internet Explorer 4.0x.')"></P>

The P element in Navigator 4.0x does not support any event handlers, so this definition does not work. In fact, you can find out for yourself by clicking these words, because we have specified an onclick event handler for this paragraph. The alert dialog box should pop up if you are running Internet Explorer 4.0x. Otherwise nothing occurs when you click the paragraph.

http://www.internet.com


Created: January 13, 1998
Revised: January 14, 1998

URL: http://www.webreference.com/js/column11/elements.html