avoiding dom irregularities using dynamic css is my way, but there are millions...
using html like
Code:
<div id="sched">
<div class="mon">
<span class="hour h8">all things considered</span>
<span class="hour h9">all things considered</span>
<span class="hour h10">news</span>
<span class="hour h11">weekly outlook</span>
<span class="hour h12">lunchbox concert</span>
</div>
</div>
and this exact script
Code:
function setTimecode(){
var weekday=new Date(+new Date -new Date().getTimezoneOffset()*60000).toGMTString().split(",")[0].toLowerCase();
var hour= "h" +new Date().getHours();
document.body.setAttribute("data-dt", hour+" "+weekday);
}
setTimecode();
setInterval(setTimecode, 20000);
with expanded css along the lines of this
Code:
/* turn off all days */
[data-dt~=tue] #sched .mon,
[data-dt~=tue] #sched .tue,
[data-dt~=tue] #sched .wed,
[data-dt~=tue] #sched .thu,
[data-dt~=tue] #sched .fri,
[data-dt~=tue] #sched .sat,
[data-dt~=tue] #sched .sun{ display: none;}
/*turn off all hours */
#sched .hour { display:none; }
/* now, opt-in for each known day */
[data-dt~=mon] #sched .mon{ display: block; }
[data-dt~=tue] #sched .tue { display: block; }
[data-dt~=wed] #sched .wed{ display: block; }
/* (do other days here...) */
/* now un-hide the proper hour */
[data-dt~=h8] #sched .h8 ,
[data-dt~=h8] #sched .h9 ,
[data-dt~=h8] #sched .h10,
[data-dt~=h8] #sched .h11,
[data-dt~=h8] #sched .h12 {display: block !important;} /* do other hours as well... */
the time is updated every 20 seconds automatically.
while this can be repetitive, it avoids a lot of complex programming and x-browser bugs.
it also lets you put the display logic in css, where it belongs.
Bookmarks