I'm sorry if this is a duplicate, but I can't find an existing answer that matches my question (I have looked!).
I have a list with about a dozen items each with a <span>*fixed date*</span>
.
The list containing the dates looks like so....
<ul id="whatson">
<li>
<span class="chkdate">06/04</span>
somestuff1
</li>
<li>
<span class="chkdate">06/05</span>
somestuff2
</li>
.......
</ul>
I want to filter the list so all dates older than today are hidden.
will give me todays date e.g. mm/dd = 06/04, that seems fine.
I now want to check this against each list item formatted as e.g. 06/04 and hide those items that are earlier than today.
It only needs to function once, on page load.
my code so far...
$(document).ready(function () {
var d = new Date();
var month = d.getMonth() + 1;
var day = d.getDate();
var todaysdate = (month < 10 ? '0' : '') + month + '/' + (day < 10 ? '0' : '') + day;
alert("checking " + datetocheck + " against today = " + todaysdate);
--- * temp check *
var datetocheck = $('#whatson li span.chkdate').text();
if (datetocheck < todaysdate) {
$('#whatson li').hide();
} else {
$('#whatson li').show();
};
})
My alert shows..
Checking 06/0406/04 against today 06/04 *(when all list dates match)*
and displays correctly.
Changing one or more list dates the alert displays
Checking 06/0306/04 against today 06/04 *(when one or more list dates don't match)*
and nothing is shown.
Can you help, I thought this would be straight forward but just can't get a result?