Results 1 to 2 of 2

Thread: CSS with Javascript??

  1. #1
    Join Date
    Mar 2010
    Location
    Canada
    Posts
    32
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default CSS with Javascript??

    I am able to incorporate CSS into the HTML, like this:
    Code:
    <tr><td style="background-color:#FFFF00;">test</td></tr>
    How can I incorporate CSS into javascript?
    Code:
    document.writeln("<tr><td style="background-color:#FFFF00;">" + "test" + "</td></tr>");
    The javascript code doesn't work or this is it even possible?

    Thanks

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You are using quotes " to tell Javascript where the string ends. So when you also use it to start and end the HTML property, it makes things confusing and it doesn't parse correctly.

    Simply replace the embedded "s with \".

    Code:
    document.writeln("<tr><td style=\"background-color:#FFFF00;\">" + "test" + "</td></tr>");
    Alternatively you can alternate single and double quotes. It looks a bit more elegant, though it can be a little harder to remember.
    Code:
    document.writeln('<tr><td style="background-color:#FFFF00;">' + 'test' + '</td></tr>');
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •