Thanks and @alfraser86 @gestchild for help with this.
Last active
August 29, 2015 14:03
-
-
Save maban/aeebc9670cfa2b3f14a8 to your computer and use it in GitHub Desktop.
Turns the text red if the date given in the datetime attribute is in the past
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.expired { | |
color: red; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> | |
<time class="expiration-date" datetime="2012-06-27">27-06-2012</time> | |
<time class="expiration-date" datetime="2015-06-27">27-06-2025</time> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var now = new Date(); | |
$('.expiration-date').each(function() { | |
if (now < new Date($(this).attr('datetime'))) { | |
$(this).addClass('unexpired'); | |
} | |
else { | |
$(this).addClass('expired'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment