Firstly, how can I have jQuery continuously check the time, and add an id
to a <div>
tag if the current time is in between two set times? I'm making a clock for a school (where the clock is a website sent over cable to TVs in every room), where each period is expressed like this:
<div class="period 1">Period 1: 7:32-8:14</div>
I'm getting the start time and end time from DataMapper, so really, the code in the view (an eRB file) is:
<% @periods.each do |@period| %>
<div class="period <%= @period.id %>"><%= @period.string %>: <%= @period.start_time.strftime("%I:%M") %>–<%= @period.end_time.strftime("%I:%M") %></div>
<% end %>
My question is how I can get jQuery to continuously check the current time, and if it is in between @period.start_time
and @period.end_time
. If so, add id="active"
to the <div>
.
Would I have to set up something for JavaScript to interface with Ruby via .get
?
If you have any questions, please ask.