Dan
Dan

Reputation: 13

Changing text depending on current time?

I've only had a very quick preliminary search but is it possible to automatically change a specific element with javascript or jquery depending on the time?.. or by the local time of the computer who is viewing the webpage.

For instance say I have a <h2>Good Morning</h2> display before 12pm, and then automatically it would change to to <h2>Good Afternoon</h2> once it gets past this time.

I honestly, have not looked very deep into at all, but just wondering if this possible, and if so, is there a particular plugin that would aide me with this/what is the best way to do it?

Upvotes: 1

Views: 6807

Answers (3)

Jayachandran Murugesh
Jayachandran Murugesh

Reputation: 111

The text changes, might be done using cron job , if it is possible , you can do it just add or activate the css for the same element.

Upvotes: 0

Casey Rule
Casey Rule

Reputation: 2085

Javascript's Date object is you best bet to get the time.

http://www.w3schools.com/jsref/jsref_obj_date.asp

Once you know the time, it's easy to change the text in the header.

Upvotes: 0

SeanCannon
SeanCannon

Reputation: 77956

Don't need jQuery.

document.getElementById('greeting').innerHTML = new Date().getHours() >= 12 ? 'Good Afternoon' : 'Good Morning';

Upvotes: 7

Related Questions