I looked at several entries on here related to this, but none specifically for alphanumeric sorting. Tried A LOT of ways today, but got no where, so I looking for help.
HTML
<div id="chartEntries">
<div class="divEntry" rval="BBB">
<div class="ori" style="display:none;">BBB</div>
<h3>Value</h3>
<span>BBB - I should come in 2nd.</span>
</div>
<div class="divEntry" rval="DDD">
<div class="ori" style="display:none;">DDD</div>
<h3>Value</h3>
<span>DDD - I should come in 4th.</span>
</div>
<div class="divEntry" rval="AAA">
<div class="ori" style="display:none;">AAA</div>
<h3>Value</h3>
<span>AAA - I should come in 1st.</span>
</div>
<div class="divEntry" rval="CCC">
<div class="ori" style="display:none;">CCC</div>
<h3>Value</h3>
<span>CCC - I should come in 3nd.</span>
</div>
</div>
I want to return the sorted .divEntry DIVs unchanged back into the #chartEntries DIV.
Tried
function sorter(a,b){
return $(a).data('rval') > $(b).data('rval');
}
var orderedDivs = $('.divEntry').sort(sorter);
$("#chartEntries").html(orderedDivs);
also tried with .getAttribute('rval'). Any thoughts?
jsFiddle -> https://jsfiddle.net/mweidlick/tb6xpfkk/40/
data-.