PDA

View Full Version : changing multiple elements at once


devonrs
06-18-2006, 02:09 AM
This seems like it should be really simple, but I can't find a solution.

I want to be able to change an attribute (say, background-color) of multiple divs with one link. but the divs are all the same, for example, everytime i post a news update, there's a new div, so i want to be able to change the background color of all of them at once, no matter how many there are.

If I give them all the same ID, a link only changes the color of the first one.

I've been searching the web, but only find different ways to change one element at a time (i.e. document.getElementByID("element").style.backgroundColor = '#color'")

If I did it that way, I'd have to add another line for element2, element3, element4, and so on, every time I made a new div.

Is there a way to change the attribute of an entire class all at once?

thanks..

devonrs
06-18-2006, 03:28 AM
nevermind... after hours of messing around, i finally figured it out..

onclick="document.styleSheets[0].cssRules[0].style.backgroundColor='green'"


whew!