Expandable Outlines: Internet Explorer 4 (cont'd) | WebReference

Expandable Outlines: Internet Explorer 4 (cont'd)

Logo

Expandable Outlines
Explorer 4: using toggled images


Click the triangles to expand the headings: (IE4 only)

Expand/Collapse Item World Wide Web Consortium (W3C)

Expand/Collapse Item Netscape

Dynamic HTML documentation   Updated!
http://developer.netscape.com/library/documentation/
communicator/dynhtml/index.htm

Recently updated for Communicator final release with better CSS documentation and examples. An invaluable reference for developers, the complete documentation can be viewed online, or downloaded as:

In the first example, above, the image is contained in a link, as our first example on the previous page:

    <H3> <A HREF="javascript:expandIt(elOne)"> <IMG SRC="triDown.gif" WIDTH=16 HEIGHT=16 BORDER=0 ALT="Expand/Collapse Item"></A> World Wide Web Consortium (W3C)</H3> <P ID="elOne" STYLE="display:none"> . . . </P>

The expandIt() function is modified to swap images, to reflect the expanded/collapsed state of the element:

    function expandIt(whichEl) { whichIm = event.srcElement; if (whichEl.style.display == "none") { whichEl.style.display = ""; whichIm.src = "triUp.gif"; } else { whichEl.style.display = "none"; whichIm.src = "triDown.gif"; } }

Notice that the image to be swapped is identified as event.srcElement. That is, the element that received the event (click). Although the click was meant for the link (A) element, Explorer's bottom-up approach to event handling identifies the IMG as the event source element, and since this element does not define an action for the event, it is passed up to the A.

Explorer event handling is discussed in Dynamic Images, in the context of the column examples, and generally, in Doc JavaScript's The Internet Explorer Event Model.

The second example avoids the link, and uses onClick as an event handler of IMG.

    <H3> <IMG SRC="triDown.gif" WIDTH=16 HEIGHT=16 BORDER=0 ALT="Expand/Collapse Item" onClick="expandIt(elTwo)" STYLE="cursor:hand"> <-- see note below Netscape</H3> <DIV ID="elTwo" STYLE="display:none"> . . . </DIV>

Notes: The ALT attribute is displayed by both DHTML browsers when the mouse is over the image. This new behaviour makes ALT a "hint" or "extra info" attribute as well as a label for non-graphical or images-off browsers. Use it to provide information on links or click actions.
When Navigator 4 parses the STYLE attribute in the IMG tag, it renders the IMG and possibly succeding elements incorrectly. Although cursor:hand is a helpful property here, it should be used only in Explorer-specific applications.

The complete Explorer code is repeated in our first code page.

I know, it's not challenging. The same, however, cannot be said for the Navigator version!


Produced by Peter Belesis and

All Rights Reserved. Legal Notices.
Created: Jan. 14, 1998
Revised: Jan. 18, 1998

URL: http://www.webreference.com/dhtml/column12/outIEtwo.html