Display latest date from a HTML attribute
Posted
by
Tron
on Stack Overflow
See other posts from Stack Overflow
or by Tron
Published on 2013-11-11T15:50:33Z
Indexed on
2013/11/11
15:53 UTC
Read the original article
Hit count: 229
I currently have several classes which contain a date inside an attribute.
<div id="container">
<div class="date" date="19/11/2013"></div>
<div class="date" date="06/11/2013"></div>
</div>
<div id="result"></div>
What I would like to do, is find the latest date and display it on the page. So far, I've found the information in the attribute, checked that it doesn't exist in the array then and pushed it into an array. I'm not entirely sure of the best approach from here, but ideally i would like to find the latest date and then append it to the results container.
$('.date').each(function () {
var dateArray = [];
var date = $(this).attr('date');
if ($.inArray(date, dateArray) == -1) {
dateArray.push(date);
}
$('#result').append(dateArray);
});
Any assistance on the above would be greatly appreciated.
Thanks :)
© Stack Overflow or respective owner