jquery - Continuously Check Time -


First of all, how can i check jQuery continuously and id > & Lt; Div & gt; Tags if the current time is between two set bars? I'm making a clock for a school (where the clock is a website that is sent to the cable on the TV in each room), where each period is expressed as such:

  Lt; Div class = "period 1" & gt; Duration 1: 7: 32-8: 14 & lt; / Div & gt; In fact, the code in the view (an ERB file) is:  
     

% @ Periods.each do | @period | & Gt%; & Lt; Div class = "duration"% = @ period.id%> & Gt; & Lt;% = @ period.string%>: & lt;% = @ period.start_time.strftime ("% I:% M")% & Gt; & Amp; Ndash; & Lt;% = @ period.and_time.startfight ("% I:% M")%> & Lt; / Div & gt; & Lt;% end% & gt;

My question is how can I constantly check time, and if it is between the @ period Start_time and @period end_time . If so, then id = "active" to and

.

Add. Do I have to set some for javascript to interface with ruby ​​ .get ?

If you have any questions, please ask.

You can get it by using the date () object of javascript Are there. Revision due to clarification of the question

CSS

 . Active {font-weight: bold; } // or whatever style you have  

javascript

  var loop = setInterval (function () {var d = new date ()} var dh = D.getHours (); var CP = 16; / * CP is your preliminary period before 1600, but it is for me to work with an hour each with increment at present time (8 o'clock) . $ / * ('(' Active '); $ (this) .addClass (' active '); // current and $ (if this add) activate .removeClass (' active '); / / otherwise it is cp + + Remove; // Add one hour each loop Let's assume that each period is 1hr}};}, 60000); // 60000 milliseconds = 1 minute update  

link to check

Live example -
Live example 2 (Modification) -
About Date () -


Comments