[thelist] DHTML Question
Matt Warden
mwarden at gmail.com
Thu Jul 7 15:44:19 CDT 2005
On 7/7/05, Scott Wehrenberg <swehren at gmail.com> wrote:
> On 7/7/05, Steve James <steve at epicunion.com> wrote:
> > I want to make a global change to all divs using javascript, but they
> > don't have ID's (trying to make this XHTML compliant). Is there a way to
> > do something to the affect of:
> >
> > document.div.style.visibility = "hidden";
> >
>
> divs = document.getElementsByTagName('div');
> for(var i in divs)
> {
> divs[i].style.visibility = 'hidden';
> }
Careful, there. Your loop isn't going to work like you expect. This is
because properties in JS are implemented as an associative array, and
they'll end up as keys in your for loop. So, you're going to get a
bunch of errors stating that, for example, divs[length] is not an
object. See:
http://mwarden.f2o.org/sandbox/jsforeachtest.htm
--
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com
This email proudly and graciously contributes to entropy.
More information about the thelist
mailing list