spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / dhtml / column12
Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management
Logo

Expandable Outlines
Navigator 4: expanding and collapsing elements


When our page has finished loading and all our elements are correctly placed, we need to immediately hide the expandable outline elements, and reposition the visible ones. In our script, we place an onLoad event handler:

Initialization

When the init() function is called (on page load), it first moves through all the positioned elements in the page, starting with the second outline element (firstInd+1), searching for those with the string "Child" in their ID. (It would be an excellent idea to reserve "Child" for expandable element identification only.) If such an element is found, its visibility property is set to hide. (A discussion of the merits of show/hide vs visible/hidden in Navigator-only code can be found in column 10, DHTML Jigsaw Puzzle, Navigator version.

Once all our outline child elements have been hidden, arrange() is called to reposition the elements. This time through, all collapsable elements will be skipped, resulting in just the outline heads visible, positioned in order.

Expanding/Collapsing on Demand

Recall from the previous page that our call to the expandIt() function is this link:

Since we are, as usual, building up to a cross-browser and backward-compatible code, the function call has been placed in the onClick handler, returning false to cancel the HREF for JavaScript browsers. We also now pass a string to expandIt(), instead of the element reference. Non-JavaScript browsers will get the dummy # value for HREF. Notice that all link images have the same NAME value, imEx.

The expandIt() function (Navigator version), first identifies the element to be manipulated by adding the document. prefix and Child suffix to the passed string. For example, elOneParent passes "elOne" to expandIt(), making whichEl equal to: document.elOneChild.

The image to be swapped is identified in a similar way, with the same prefix, and a suffix of Parent.document.images["imEx"]. In the example above, (whichIm) would be: document.elOneParent.document.images["imEx"].

Once the element to be expanded/collapsed and the relevant image are determined, expandIt() simply toggles the values of the element's visibility property and the image's src property.

Finally, arrangeIt() is called to reposition the elements.

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

For now, however, let's create a cross-browser version.


Produced by Peter Belesis and

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

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

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