I have a table of dates that I am trying to highlight the current line based on the date. and change the class of the previously active row to past.
As you can see the first row the class has been set to past, the second row is active and all future rows are future.
I found a js snippet that seems like it will work but I am having no luck getting it to work
I am not well versed in JS so if anyone can offer assistance to get this working I sure would appreciate it. TIA Steve
Here are the next few table rows.
<TR class="past">
<TD>1909</TD>
<TD>Aug - 06</TD>
<TD>Aug - 15</TD></TR>
<TR class="active">
<TD>1910</TD>
<TD>Sep - 03</TD>
<TD>Sep - 12</TD></TR>
<TR class="future">
<TD>1911</TD>
<TD>Oct - 01</TD>
<TD>Oct - 10</TD></TR>
<TR class="future">
<TD>1912</TD>
<TD>Oct - 29</TD>
<TD>Nov - 07</TD></TR>
<TR class="future">
<TD>1913</TD>
<TD>Nov - 26</TD>
<TD>Dec - 05</TD>
and this is the JS that I am trying to get working.
<script type="text/javascript">
$(document).ready(function () {
$( ".class" ).each(function() {
var text=$(this).text();
var res = text.split(" ");
var resta = res[1].split("/");
var dd=resta[0];
var mm=resta[1];
var yy=resta[2];
var now_date = new Date(); //"now"
var duedate = new Date(mm+'/'+dd+'/'+yy);
var diff = Math.abs(now_date-duedate);
var each_day = 1000 * 60 * 60 * 24;//milliseconds in a day
var days = Math.round(diff / each_day);
if(days <= 0)
$(this).removeClass("future").addClass("active");
if(days <= -1)
$(this).removeClass("active").addClass("past");
});
</script> -->