2

I wrote a javascript code displaying the date. How would I change the color?

0

2 Answers 2

6

You need to put the text in a separate element, then change the element's color CSS property.

This is easiest to do using jQuery:

<span id="date">Please enable JavaScript</span> $('#date').text(new Date().toString()).css('color', 'red'); 

However, you might want to do it with pure CSS:

(In the head tag:)

<style type="text/css"> #date { color: red; } </style> 
Sign up to request clarification or add additional context in comments.

1 Comment

Your 'l' at the end should be a semicolon :-)
5

You could set inline CSS properties of the element where you display the date, by using the element.style property:

var el = document.getElementById('elementId'); el.innerHTML = date; // set the text el.style.color = '#ff0000'; // set the text color 

Or you could apply a CSS class programmatically:

el.className = 'yourclass'; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.