大家好,请帮助我找不到错误
当我按排序时......它会一次又一次地排序
html:
<div class="unsorted">
<div class="labelimagediv" rel="5">
Div 5 here
</div>
<div class="labelimagediv" rel="3">
Div 3 Here
</div>
<div class="labelimagediv" rel="4.5">
Div 4.5 here
</div>
<div class="labelimagediv" rel="4">
Div 4 Here
</div> </div>
<button class="btnSort">Sort</button>
javascript:
$("button.btnSort").click(function () {
var item1 = $('div.labelimagediv')[0];
var sortedDivs = $(".unsorted").find(item1).toArray().sort(sorter);
$.each(sortedDivs, function (index, value) {
$(".unsorted").append(value);
});
});
function sorter(a, b) {
return a.getAttribute('rel') - b.getAttribute('rel');
};