0

Hi, i am new to this forum after seeing different valuable replies i am posting my query..
Need a HTML script that can define the background color a text with respect to time.. for ex. i have some five texts say 1hr,2hr,3hr,4hr,5hr.

Now my script should check the local time and then decide the background color of the text.

is there any solution for this, please let me know.

3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by kylegetson
0

Is there any sample that you can provide me u with both options javascript and server side implementation

Javascript is probably the best method for this. But you could also do it in any server side implementation as well.
javascript date and time

0

suppose you have ids of text elements as you mention:
"1hr, 2hr, 3hr, 4hr, 5hr...."

javascript: var  D = new Date(); var h = D.getHours();
document.getElementById(h+'hr').style.backgroundColor = "red"

that would set the correct text element background color to a (highly) distinctive color there. :')
If you'd like it current without refreshing the page you should use a timer check...

0

Is there any sample that you can provide me u with both options javascript and server side implementation

I would do something like:

var currentTime = new Date()
var hours= currentTime.getHours() 
if(hours < 11){
document.getElementById('greetingID').style.color = '#ff0000';
}

This would make the text color red, if it was before 11am. You could expand on that if statement to better match what you need, but you get the idea.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.