[thelist] DHTML - div display.

Matt Warden mwarden at gmail.com
Sun Feb 6 19:30:30 CST 2005

On Sun, 6 Feb 2005 18:51:29 -0000, Gormley <Robert> wrote:
> What I have is this, in structure:
> <div id="contentContainer">
> <div id="client1">
> blah
> </div>
> <div class="clientExpanded" id="client1expanded">
> blah
> </div>
> </div>
> What would be a solution that would work... ideally with the ability to take
> an argument, so i could do onclick='expand(this)' (actually, the this comes
> to mind now, so that might not be necessary)... and that sets the
> appropriate div id to display, and walks all the other .clientExpanded#s to
> set them display none?

var divs = document.getElementByTagName('div');
// using, instead:
// document.getElementById('contentContainer').getElementByTagName('div');
// could save you some iterations, if appropriate
for (var i=0; i<divs.length; i++)
      if (divs[i].className=='clientExpanded')

Make sure you are setting the onclick property appropriately if you
are going to use 'this'. See PPK's excellent explanation here:


This assumes that the div only can have one class name. You would need
to use indexOf and appropriately replace/append the class name if
there can be more than one.

Matt Warden
Miami University
Oxford, OH, USA

This email proudly and graciously contributes to entropy.

More information about the thelist mailing list