0

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?

Thanks

5
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by Pnorq
0

check this is working:

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

As Shanti said, the fix is to escape your double quotation in your string. The way you do creates an unterminated string.

/*
document.writeln("<tr><td style="background-color:#FFFF00;">" + "test" + "</td></tr>");
|----------------|--------------|-------------------------|-|
^                ^              ^            ^            ^ ^
|                |              |            ^            | |
start            start          end        expect         start
command          string         string     expression     string
                                                            end
                                                            string
*/

Edited by Taywin: n/a

0

Use jQuery. It is a complete waste of time to use document.writeln() and it doesn't lend itself to dynamic behaviors.

eg,

html: <tr><td id='demoItem'>blah blah</td></tr>

javascript: $('#demoItem').css('background', '#FFFF00');

If you learn to use jQuery, you gain access to a million useful utilities and functions. Go for it!!

0

I totally agree with tqwhite above. The time spent learning JQuery will pay huge dividends. Just for clarity, what JQuery is doing under the covers is essentially this (using tqwhite's example):

html: <tr><td id='demoItem'>blah blah</td></tr> writing the JavaScript yourself:

var el = document.getElementById("demoItem");
el.style.backgroundColor = "#FFFF00";
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.