Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

dynamic styles and classes

0 views
Skip to first unread message

dud ley

unread,
Sep 18, 2001, 4:59:47 PM9/18/01
to
Can i dynamically set a style after a page has loaded.

e.g. I have a class with display: none; I want to change that class to have
display:block. So every element using that class would change accordingly.

Is this posible?

cheers
dud


Wired Earp

unread,
Sep 19, 2001, 9:12:18 AM9/19/01
to
You can build an array of all elements of a certain kind, scan for a
given classname and adjust the display property of the elements found
[according to it's present state - as in the example below]

var divList = document.getElementsByTagName("div");
for (i=0; i<divList.length; i++) {
if (divList[i].className == "johnson") {
with (divList[i].style ) {
display == "none" ? display = "block" : display = "none";
}
}
}

--
Wired Earp
Wunderbyte

Ekevu Cheetah

unread,
Sep 19, 2001, 4:23:40 PM9/19/01
to
Mwa, Wired Earp!

> display == "none" ? display = "block" : display = "none";

A more intelligent construct (and the whole purpose of the ?: operator) is:

display = (display=="none") ? "block" : "none";

These parenthesis are optional due to precedence rules.

· · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
· ·
· PEACE ·
· ·
· Ekevu Cheetah · http://www.felin.com.br · uin: 32125925 ·


0 new messages