我想重新排列它們包含的某些值的基礎上的divs。我的代碼如下重新排列科和他們的孩子
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>
等等......
在改變稱爲#data_filter過濾器,我想主要的div(那些content_id_something)和他們的全部內容是重新排序的日期值...我試圖適應下面的示例(http://stackoverflow.com/questions/2501789/jquery-sort-divs-according-to-content-of-different-sub-divs),但我有點失落...... 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);
});
}) ;
非常感謝您的幫助!
其實,'''必須被刪除。更新答案。 –
非常感謝你Tentonaxe! '確實是一個錯字 – Raphael