Hello, I'm trying to sort a list by char-date. I need you to keep it in descending order. I do not understand much of javascript / jquery, but through my searches, I got to the code below. But he is returning the order to me: c8 c2 b1 b13 a20 a18 a8 a2 a7, he needed everything to be in descending order: c8 c2 b13 b1 a20 a18 a8 a7 a2. what am I doing wrong? Here is Jsfiddle. Thank you.
$(".pecas li").sort(sort_li).appendTo('.pecas');
function sort_li(a, b) {
var va = $(a).data('char').toString().charCodeAt(0);
var vb = $(b).data('char').toString().charCodeAt(0);
if (va < 'a'.charCodeAt(0)) va += 100;
if (vb < 'a'.charCodeAt(0)) vb += 100;
return vb > va ? 1 : -1;
}
li{list-style:none}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><olclass="pecas">
<li class="foto" data-char="a20">a20</li>
<li class="foto" data-char="a18">a18</li>
<li class="foto" data-char="c8">c8</li>
<li class="foto" data-char="a8">a8</li>
<li class="foto" data-char="a2">a2</li>
<li class="foto" data-char="a7">a7</li>
<li class="foto" data-char="b1">b1</li>
<li class="foto" data-char="c2">c2</li>
<li class="foto" data-char="b13">b13</li>
</ol>