Can I use replace a class @cls@ with a variable from a script?

I’m trying to stripe my odd/even invoice lines, but each invoice line comprises multiple rows in the table. So I want to create a script to replace a class variable with an .css class, either “even” or “odd”. Each table row that I want striping on would look something like .

Is this even possible? And if so, how?

Thanks, Rick

Hello Rick,

While technically this could be done with a script, there’s a much simpler (and especially effective) way: using a CSS selector.

In CSS, you can create a selector that will do this easily: the “even” and “odd” selector. Basically, you can have code like this:

tr:nth-child(even) {background-color: #CCC;}

This means every even row now has a background color that’s grey. tr:nth-child(odd) will of course control the odd rows.

We actually use this in our dynamic table wizard, and the code is there by default in our temples: just look at the “default.css” stylesheet, it’s all there!

~Evie

That’s the trouble… each line row is made up of multiple rows…using scripts, so the nth child doesn’t work.

FYI i’m using nested tables. It’s getting really fun with scripts ;).

Ah, I see what you’re doing… In that case, yes you will need to apply specific classes to your rows.

The way you would do this within the script is… well, just add class=“odd” to the code as you’re building it, if you’re building the row as a simple string and appending it somewhere? Otherwise, you can change the class of an element using a query: query(“#myrow”).attr(“class”, “odd”); … but that would be difficult if they’re not already identified, so you have to make sure your script actually does that to start with.

Hard to say exactly how without seeing the actual script, however.