以下は私のhtml構造です:
<div class="qotd">
<div class="inner">
text1
1
2
</div>
</div>
上記の構造を異なる数で8回繰り返す。
i have ahref tags acting as buttons to sort the p
based on the uptext
and downtext
Sort by upvotes
Sort by downvotes
私はupvotesまたはdownvotesに基づいて段落を並べ替えるために、次のjqueryを書いた:
$(function){
$("#pos").click(function(e) {
console.log("up");
e.preventDefault();
$('.inner').sort(function(a, b) {
return parseInt($('.uptext', b).text(), 10) - parseInt($('.uptext', a).text(), 10) ;
}).appendTo('div.qotd');
});
$("#neg").click(function(e) {
console.log("down");
e.preventDefault();
$('.inner').sort(function(a, b) {
return parseInt($('downtext', b).text(), 10) - parseInt($('.downtext', a).text(), 10);
}).appendTo('div.qotd');
});
}
The jsfiddle is here
Despite all the above i do not get the correct result, where am i going wrong?