Change text color for one document.write but not color of all text?

Discussion in 'Javascript' started by kroger@princeton.edu, Jan 29, 2005.

  1. Guest

    Hi, one part of my website is at:

    http://www.psych.nmsu.edu/~jkroger/lab/undergrads.html



    I want to make the date at the top right darker blue.
    But when I do that, all the light blue text next to
    the pictures also changes.

    How can I control the color of the result of
    document.write output without changing the
    forground color of the entire page? Note my
    document write includes variables, so I was
    hesitant to imbed an html command in the
    document.write.

    Thanks much in advance for any pointers....
    Jim
     
    , Jan 29, 2005
    #1
    1. Advertising

  2. <> wrote in message
    news:...
    > Hi, one part of my website is at:
    >
    > http://www.psych.nmsu.edu/~jkroger/lab/undergrads.html
    >
    >
    >
    > I want to make the date at the top right darker blue.
    > But when I do that, all the light blue text next to
    > the pictures also changes.
    >
    > How can I control the color of the result of
    > document.write output without changing the
    > forground color of the entire page? Note my
    > document write includes variables, so I was
    > hesitant to imbed an html command in the
    > document.write.
    >
    > Thanks much in advance for any pointers....
    > Jim
    >


    var i=12345;

    document.write("I'm GREEN text and here's a variable in red:
    ".fontcolor('green') +i.toString().fontcolor("red"));

    --
    S.C.
     
    Stephen Chalmers, Jan 30, 2005
    #2
    1. Advertising

  3. RobG Guest

    wrote:
    > Hi, one part of my website is at:
    >
    > http://www.psych.nmsu.edu/~jkroger/lab/undergrads.html
    >
    >
    >
    > I want to make the date at the top right darker blue.
    > But when I do that, all the light blue text next to
    > the pictures also changes.
    >
    > How can I control the color of the result of
    > document.write output without changing the
    > forground color of the entire page? Note my


    Wrap it in a <span> with the appropriate colour. Your
    "get date" function is a bit rough too, suggested
    improvement below.

    Using arrays for months and days is considerably more
    efficient than your multiple if's.

    > document write includes variables, so I was
    > hesitant to imbed an html command in the
    > document.write.


    HTML is not "commands", it is markup that is interpreted.
    It may seem a trivial point, but there you go. You have
    no other way of controlling the colour of the element
    than using markup, so use it. I have used a span and style,
    but you could use a class too.



    <html>
    <head>
    <title>play</title>
    <script type="text/javascript">

    function clientDate(){
    var months = ['January','February','March',
    'April','May','June','July',
    'August','September','October',
    'November','','December'];

    var days = ['Sunday','Monday','Tuesday',
    'Wednesday','Thursday','Friday',
    'Saturday'];

    var now = new Date();

    return days[now.getDay()]
    + ', ' + months[now.getMonth()]
    + ' ' + now.getDate()
    + ', ' + now.getFullYear();
    }
    </script>
    </head>
    <body>
    <script type="text/javascript">
    document.write('<span style="color: #333366">' +
    clientDate() + '</span>');
    </script>
    </body>
    </html>

    --
    Rob
     
    RobG, Jan 30, 2005
    #3
  4. Mick White Guest

    Re: Change text color for one document.write but not color of alltext?

    RobG wrote:
    > wrote:
    >
    >>Hi, one part of my website is at:
    >>
    >>http://www.psych.nmsu.edu/~jkroger/lab/undergrads.html
    >>
    >>
    >>
    >>I want to make the date at the top right darker blue.
    >>But when I do that, all the light blue text next to
    >>the pictures also changes.
    >>
    >>How can I control the color of the result of
    >>document.write output without changing the
    >>forground color of the entire page? Note my

    >
    >
    > Wrap it in a <span> with the appropriate colour. Your
    > "get date" function is a bit rough too, suggested
    > improvement below.
    >
    > Using arrays for months and days is considerably more
    > efficient than your multiple if's.
    >
    >
    >>document write includes variables, so I was
    >>hesitant to imbed an html command in the
    >>document.write.

    >
    >
    > HTML is not "commands", it is markup that is interpreted.
    > It may seem a trivial point, but there you go. You have
    > no other way of controlling the colour of the element
    > than using markup, so use it. I have used a span and style,
    > but you could use a class too.
    >
    >
    >
    > <html>
    > <head>
    > <title>play</title>
    > <script type="text/javascript">
    >
    > function clientDate(){
    > var months = ['January','February','March',
    > 'April','May','June','July',
    > 'August','September','October',
    > 'November','','December'];


    Empty string between Nov and Dec?
    Mick


    >
    > var days = ['Sunday','Monday','Tuesday',
    > 'Wednesday','Thursday','Friday',
    > 'Saturday'];



    >
    > var now = new Date();
    >
    > return days[now.getDay()]
    > + ', ' + months[now.getMonth()]
    > + ' ' + now.getDate()
    > + ', ' + now.getFullYear();
    > }
    > </script>
    > </head>
    > <body>
    > <script type="text/javascript">
    > document.write('<span style="color: #333366">' +
    > clientDate() + '</span>');
    > </script>
    > </body>
    > </html>
    >
     
    Mick White, Jan 30, 2005
    #4
  5. RobG Guest

    Quite right, but frankly I'd rather December was banished from the
    calendar, then I'd not get any older...

    --
    Rob
     
    RobG, Jan 30, 2005
    #5
  6. Guest

    Wow, thanks Rob for the help with text color on my dates! I learned a
    lot!

    Thanks to you as well, S.C. ....

    Great place, usenet....

    Jim
     
    , Jan 31, 2005
    #6
  7. Guest

    Say, Rob, why do you put the function declaration in the head, and the
    call in the body?

    Thanks
    Jim



    ---------------

    <html>
    <head>
    <title>play</title>
    <script type="text/javascript">

    function clientDate(){
    var months = ['January','February','March',
    'April','May','June','July',
    'August','September','October',
    'November','','December'];

    var days = ['Sunday','Monday','Tuesday',
    'Wednesday','Thursday','Friday',
    'Saturday'];

    var now = new Date();

    return days[now.getDay()]
    + ', ' + months[now.getMonth()]
    + ' ' + now.getDate()
    + ', ' + now.getFullYear();
    }

    </script>
    </head>
    <body>
    <script type="text/javascript">
    document.write('<span style="color: #333366">' +
    clientDate() + '</span>');
    </script>
    </body>
    </html>
     
    , Feb 2, 2005
    #7
  8. Mick White Guest

    Re: Change text color for one document.write but not color of alltext?

    wrote:

    > Say, Rob, why do you put the function declaration in the head, and the
    > call in the body?
    >


    Because that's where you want the date to display.
    Mick
     
    Mick White, Feb 2, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lukasz Indyk
    Replies:
    1
    Views:
    1,497
    Andrew Thompson
    Sep 22, 2004
  2. Matt Adams
    Replies:
    0
    Views:
    912
    Matt Adams
    Aug 26, 2003
  3. Jim Ley
    Replies:
    3
    Views:
    222
  4. wk
    Replies:
    5
    Views:
    192
    Dietmar Meier
    Apr 22, 2005
  5. apparker
    Replies:
    10
    Views:
    386
    apparker
    Apr 3, 2007
Loading...

Share This Page