Display latest date from a HTML attribute
- by Tron
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 :)