Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Change text color for one document.write but not color of all text?

Reply
Thread Tools

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

 
 
kroger@princeton.edu
Guest
Posts: n/a
 
      01-29-2005
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

 
Reply With Quote
 
 
 
 
Stephen Chalmers
Guest
Posts: n/a
 
      01-30-2005
<> wrote in message
news: oups.com...
> 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.



 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      01-30-2005
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

 
Reply With Quote
 
Mick White
Guest
Posts: n/a
 
      01-30-2005
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>
>

 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      01-30-2005
Quite right, but frankly I'd rather December was banished from the
calendar, then I'd not get any older...

--
Rob

 
Reply With Quote
 
kroger@princeton.edu
Guest
Posts: n/a
 
      01-31-2005
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

 
Reply With Quote
 
kroger@princeton.edu
Guest
Posts: n/a
 
      02-02-2005
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>

 
Reply With Quote
 
Mick White
Guest
Posts: n/a
 
      02-02-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shortest way to read all lines (one by one) from a text file? Robin Wenger Java 11 02-14-2011 12:08 PM
Changing font color from current font color to black color Kamaljeet Saini Ruby 0 02-13-2009 04:58 PM
change text color onclick, and change it back - will post to DB apparker Javascript 10 04-03-2007 01:57 PM
How to highlight (change background color) of selected text within a text area omidalavi@yahoo.com Javascript 0 09-23-2005 04:34 PM
Change text color of "visited link" back to unvisited color ??? Matt Adams HTML 0 08-26-2003 10:27 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57