AllExperts > Experts 
Search      

Javascript

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Javascript Answers
Question Library

Ask a question about Javascript
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Anthony Levensalor
Experience
I have been programming in Java and Javascript since 1998. I run a web development company that specializes in Ajax front ends with PHP/MySQL back ends. I am a Sun Certified Java 2 Developer, and have done nothing but web applications for the last two years in my business

Past/Present clients
Monster.com, Compuware Corporation, Flextronics International, Pragmatech Software, Open Travel Software, The Loss Mitigation Institute, Raw Story Media, Page One News Media.

 
   

You are here:  Experts > Computing/Technology > Focus on JavaScript > Javascript > Javascript, change text color when document writes

Topic: Javascript



Expert: Anthony Levensalor
Date: 11/3/2007
Subject: Javascript, change text color when document writes

Question
The text prints todays date in default black on the test page. In the code below, what variables need to be added to specify other text colors when the document writes ?

<script type="text/javascript">
           
<!--- hide from old browsers
           
           
var d=new Date();{
           
var weekday=new Array(7)
                 weekday[0]="Sunday, "
                 weekday[1]="Monday, "
                 weekday[2]="Tuesday, "
                 weekday[3]="Wednesday, "
                 weekday[4]="Thursday, "
                 weekday[5]="Friday, "
                 weekday[6]="Saturday, ";
                 document.write(weekday[d.getDay()])   
                 }            
           
var d=new Date(); {
                 
var month=new Array(12)
                 month[0]="January"
                 month[1]="February"
                 month[2]="March"
                 month[3]="April"
                 month[4]="May"
                 month[5]="June"
                 month[6]="July"
                 month[7]="August"
                 month[8]="September"
                 month[9]="October"
                 month[10]="November "
                 month[11]="December"
              document.write(month[d.getMonth()])
                 
}
           
var d = new Date(); {
              document.write(d.getDate())
                 
}
           
var d = new Date(); {
              
document.write(", " +d.getFullYear())
                 
}
           
           
//stop hiding --->
        
</script>

Answer
Try using:
document.write ("<font color='#ff0000'>" + d.getDate() + "</font>");

The write() function itself is not so much for formatting as just the raw output of whatever you put in it. Surrounding that area with fonts and other stylizing elements should turn the trick.

All the best,
~A!

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.