所以我试图通过每个<li>
. 如何定位此元素以按其值排序?
这是我当前的代码:
$("#sort_popularity").live("click", function() {
var listitems = list.children('li').get();
listitems.sort(function(a, b) {
var compA = $(a).("#subject_popularity");
var compB = $(b).("#subject_popularity");
return compA < compB;
});
$.each(listitems, function(index, item) {
list.append(item); // (List is defined elsewhere in my code)
});
});
HTML:
<a href="#" id="sort_popularity">Sort</a>
<ul>
<li><span id="popularity" data-id="10">10</li>
<li><span id="popularity" data-id="20">20</li>
<li><span id="popularity" data-id="5">5</li>
</ul>