I’m trying to reorder divs on the base of certain values they contain. My code is the following
HTML
<div id="content_id_1">
<ul>
<li> some text, not important for the reordering but it must move with it's parent div</li>
<li> some text, not important for the reordering but it must move with it's parent div</li>
<li>
<div class=‘date--2011-11-11’>2011-11-11’< /div>
</li>
</ul>
</div>
<div id="content_id_2">
<ul>
<li> some text, not important for the reordering but it must move with it's parent div</li>
<li> some text, not important for the reordering but it must move with it's parent div</li>
<li>
<div class=‘date--2011-10-10’>2011-10-10’< /div>
</li>
</ul>
</div>
And so on…
On changing the filter called #data_filter, I would like the main div (those with content_id_something) and their whole content to be reordered by the date value... I tried to adapt the following example (http://stackoverflow.com/questions/2501789/jquery-sort-divs-according-to-content-of-different-sub-divs), but I am a bit lost... JQuery :
$("#data_filter").change(function(){
function sortDateASC(a, b){
return $(a).find(div[class^=date--]) > $(b).find(div[class^=date--]) ? 1 : -1;
};
$(div[class^=date--]) .each(function(){
$(this).parent().parent().parent().sort(sortDateASC);
});
}) ;
Thank you very much for your help!