I am looking to hide/show divs with jQuery based on a specific time period throughout the day.

I am looking to hide/show divs with jQuery based on a specific time period throughout the day.

There does not need to be any animation, just visibility based on time.

Is this possible?
LVL 8
CoyotesITAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
nicawConnect With a Mentor Commented:
Sure it is! And you don't need JQuery for that either. Here's the sample code, provided you want to check time on client's side. For more javascript time functions look: http://www.tizag.com/javascriptT/javascriptdate.php
<div id="id1">Hide me</div>
<script type="text/javascript">
//<![CDATA[
//Hide id1 based on time of day
var currentTime = new Date()
if (currentTime.getHours() > 20) {
	document.getElementById('id1').style['display'] = 'none';
}
//]]>
</script>

Open in new window

0
 
aboo_sCommented:
Yes it is very possible:

Look google for a javascript that knows how to say good morning good day or good evening
and adjust it to set you div's style to visibility:block; in the morning and visibile at noon or so ...
shouldn't be a big issue!
0
All Courses

From novice to tech pro — start learning today.