I'm trying to sort div's by content date...
What i've got is sorting. But not by date...
HTML
<div id="all_elements">
<!-- one element -->
<div class="element">
<div class="display-number">02</div>
<div class="year">20-10-2011</div>
</div><!-- element -->
<!-- one element -->
<div class="element">
<div class="display-number">03</div>
<div class="year">22-09-2011</div>
</div><!-- element -->
<!-- one element -->
<div class="element">
<div class="display-number">01</div>
<div class="year">01-12-2011</div>
</div><!-- element -->
<!-- one element -->
<div class="element">
<div class="display-number">04</div>
<div class="year">01-06-2011</div>
</div><!-- element -->
<!-- one element -->
<div class="element">
<div class="display-number">05</div>
<div class="year">01-06-2010</div>
</div><!-- element -->
</div> <!--all_elements-->
JQUERY
<script>
function sortDescending(a, b) {
return $(a).find(".year").text() < $(b).find(".year").text() ? 1 : -1;
};
$(document).ready(function() {
$('#all_elements .element').sort(sortDescending).appendTo('#all_elements');
});
</script>
I know i need a function to figure out the content is a date..
Just don't know how...
Who can help me out?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…