View Full Version : changing style to multiple targets (class, id ??)

04-20-2005, 04:12 PM

I've been trying to find the answer, but none of them seems to fit my needs, so I'm asking for help now :D

Here's the thing...

I've got a huge table, dinamicaly created by php, but I can still put any tag (class, id, whatever) on those cells (about 2.000 cells). Imagine I want to change the font-color of all the cells with some tag (example: all the cells with "class=mouse" yould now have blue font)

Is there a away to do it without using "for" to visit every cells on the table?

I've been able to do something like that with this:

function test()
if (!document.styleSheets) return;
var theRules = new Array();
if (document.styleSheets[0].cssRules)
theRules = document.styleSheets[0].cssRules
else if (document.styleSheets[0].rules)
theRules = document.styleSheets[0].rules
else return;
theRules[3].style.font = 'blue'; //Edited to reflect the example, no sure if it works

But that requiered of having that class defined on the css style sheet... but I have a dinamic table, so I can't have that...

Is there a way to change that utilizing tags like class or id?
Thanks for the help


04-21-2005, 03:08 AM
If I understood you correctly, just specify this rule in your CSS and all cells of the table with id tbl will have your desired color without specifying class for each cell.

#tbl td {
<table id="tbl">