Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1096127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:14:07+00:00 2026-05-17T00:14:07+00:00

Firstly, how can I have jQuery continuously check the time, and add an id

  • 0

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") %>&ndash;<%= @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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:14:07+00:00Added an answer on May 17, 2026 at 12:14 am

    You can acheive this using Javascript’s Date() object.
    Revision due to clarification of question

    CSS

    .active { font-weight: bold; } // Or whatever styling you need
    

    Javascript

    var loop = setInterval(function() {
      var d = new Date();
      var dh = d.getHours();
      var cP = 16; 
      /* make cP your earliest period
      earlier than 1600, but that's for it to
      work with the current time for me (8pm) 
      each pass with increment by 1 hour.*/
      $('.period').each(function() {
        if (dh==cP) $(this).addClass('active'); // add active if current
        else $(this).removeClass('active'); // otherwise remove it
        cP++; // Add an hour each loop, assuming each period is 1hr
      });
    }, 60000); // 60000 milliseconds = 1 minute update
    

    ​

    Links to check out

    Live Example – http://jsbin.com/okoso3
    Live Example 2 (Revision) – http://jsbin.com/okoso3/2
    About Date() – https://developer.mozilla.org/en/JavaScript/Reference/global_objects/date

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, I have migrated my CVS repository into SVN repository. I checked out this
I have an array, which contains some duplicate entries. Firstly, is there any way
I have a data which is 100x1 vector. How can I display its empirical
Hi have noticed a few sites that give the style tag an id such
This is a two part question, but I want to make sure the first
I've been using the code from this V3 example to set up a links
Firstly, this is not a question about repository synchronisation for which there are numerous
I have a managedObject with an attribute that is a Boolean. I need to
I need a intranet portal for a Repair factory in which 100 Technician worked.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.