Robert wrote:
Is it possible to dynamically change the style of a class instead of
just an individual element? If so could you point me in the right
direction?
You can change the style(s) of a certain rule in a stylesheet with IE
and with Netscape/Mozilla/Firefox. Opera however does not support that,
not sure about latest Safari/Konqueror.
There is a collection
document.styleS heets
for all stylesheets used (<style type="text/css"> element and <link
rel="stylesheet ">).
With IE/Win each stylesheet (e.g.
document.styleS heets[someIndex]
) has a collection
document.styleS heets[someIndex].rules
with Netscape/Mozilla/Firefox the name of the collection is W3C DOM
Level 2 compliant and is
document.styleS heets[someIndex].cssRules
You can loop through those rules and find the rule by its selectorText
and then change properties defined in the rule e.g.
document.styleS heets[someIndex].cssRules[1].style.backgrou ndColor =
'blue';
Finally an inefficient way to change a class style is to add a new
stylesheet as the last stylesheet. With Opera that is your only way e.g.
var styleElement = document.create Element('style' );
styleElement.ty pe = 'text/css';
styleElement.ap pendChild(docum ent.createTextN ode(
'.className { background-color: blue }'
));
document.getEle mentsByTagName( 'head')[0].appendChild(st yleElement);
--
Martin Honnen
http://JavaScript.FAQTs.com/