jQuery If Statement and get time

jQuery If Statement and get time

Hi i am using a script which is a countdown timer - how in jQuery do i watch the countdown timer and check whether is over, in between or under a certain amount of milliseconds?

Based on the documentation and the author (the author wasn't very helpfull and refuses to help). i have came up with this.

what i want to achieve is a simple class which is added to a div based on how much time is left.

if the time left is greater than 10 minutes change div to the color green.
if the time left is between 1-10 minutes change div to orange and finally.
if the time left is under 1 minute change div to red.

I've created a fiddle of how it currently looks

there's 3 class which i want to add to the traffic-light div .green, .orange and .red based on the info above

  1. $(document).ready(function(){
  2. $('[data-countdown]').each(function() {
  3. var $this = $(this), finalDate = $(this).data('countdown');
  4. $this.countdown(finalDate, function(event) {

  5. var format = '%-Hh : %-Mm : %-Ss';

  6. if (event.offset.seconds > 600000) { //if the time is over 10minutes
  7. $("table").find(".traffic-light").addClass( "green" );
  8. } else if (event.offset.seconds > 60000-600000) { //if the time is between 1 and 10 minutes
  9. $("table").find(".traffic-light").addClass( "orange" );
  10. } else if (event.offset.seconds > 0-60000) { //if the time is between 0 and 1 minute
  11. $("table").find(".traffic-light").addClass( "red" );
  12. }

  13. $(this).html(event.strftime(format));
  14. });
  15. });
  16. });