javascript - Changing text depending on current time? - Stack Overflow

I've only had a very quick preliminary search but is it possible to automatically change a specifi

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
Add a ment  | 

3 Answers 3

Reset to default 7

Don'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

相关推荐

  • javascript - Changing text depending on current time? - Stack Overflow

    I've only had a very quick preliminary search but is it possible to automatically change a specifi

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信