Greetings.
I am trying to write a function which toggles the display of a certain
class of <div> elements in an HTML page. The CSS file initially sets some
classes to "display: none", and others to "display: block". The problem I
am encountering is that when the JavaScript interpreter starts up
initially, all style.displays are null. Thus the following code is not
effective:
function toggleAll(itemname) {
tmp = document.getElementsByTagName('div');
for (i = 0; i < tmp.length; i++) {
if (tmp[i].className == itemname) {
if (tmp[i].style.display == 'none')
tmp[i].style.display = 'block';
else
if (tmp[i].style.display == 'block')
tmp[i].style.display = 'none';
}
}
}
In the CSS file:
..foo { display: block; }
..bar { display: none; }
In the HTML file:
<a href="#" onclick="toggleAll('foo')">Show/hide foos</a>
<a href="#" onclick="toggleAll('bar')">Show/hide bars</a>
I can change the second innermost if statement to the following:
if (tmp[i].style.display == 'block' || tmp[i].style.display == '')
but this doesn't work either, since the bar class is initially hidden; the
user then needs to click the "Show/hide bars" link twice before the bars
toggle.
So I guess what I need is to query the current state of
tmp[i].style.display to see if it's "none" or "block". How do I do this?
Regards,
Tristan
--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you