CSS with Javascript?

I am able to incorporate CSS into the HTML, like this:

<tr><td [B]style="background-color:#FFFF00;"[/B]>test</td></tr>

How can I incorporate CSS into javascript?

document.writeln("<tr><td [B]style="background-color:#FFFF00;"[/B]>" + "test" + "</td></tr>");

The javascript code doesn’t work or this is it even possible?


This is a JavaScript question (some moved to that forum :wink: )

Inline code/styles like that are not the best practice, but I believe this would work, though I’m no JavaScripter:

<script type="text/javascript">
document.write("<tr><td style='background-color:#FFFF00;'>" + "test" + "</td></tr>")

You shouldn’t really be using document.write since it is far less flexible than any of the alternatives (such as using innerHTML or DOM calls).

Also it would probably be better if you had that CSS in a separate file allocated to a class and then just added the class to the <td>

you can add a class via the DOM.

document.getElementById("blah").className = "cssclass";

So if you had your style created in your css stylesheet and wanted to apply a style to that table cell, add a class to the td using the corresponding ID.