Skip to content

Instantly share code, notes, and snippets.

@maban
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maban/aeebc9670cfa2b3f14a8 to your computer and use it in GitHub Desktop.
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

Thanks and @alfraser86 @gestchild for help with this.

.expired {
color: red;
}
<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>
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