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 puter 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?
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 puter 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?
Share Improve this question asked Nov 12, 2014 at 5:37 DanDan 131 silver badge3 bronze badges 2- 1 .getHours() and .text() – Regent Commented Nov 12, 2014 at 5:40
-
1
Yes it is possible and you don't need any plugins. You just need to check the docs on the
Date
object in javascript. – Vivek Pradhan Commented Nov 12, 2014 at 5:40
3 Answers
Reset to default 7Don't need jQuery.
document.getElementById('greeting').innerHTML = new Date().getHours() >= 12 ? 'Good Afternoon' : 'Good Morning';
Javascript's Date
object is you best bet to get the time.
http://www.w3schools./jsref/jsref_obj_date.asp
Once you know the time, it's easy to change the text in the header.
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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742271153a4412722.html
评论列表(0条)