I am trying to use the .sort() function to sort a list so:
<div class="centerCnt">
<div class="widgetHelp" id="5">a</div>
<div class="widgetHelp" id="1">b</div>
<div class="widgetHelp" id="2">c</div>
<div class="widgetHelp" id="3">d</div>
</div>
I tried something like:
list = $(".widgetHelp");
list.sort(function(a, b) {
var aProp = parseInt($(a).attr('id').replace('help_id_','')),
bProp = parseInt($(b).attr('id').replace('help_id_',''));
return (aProp > bProp ? 1 : aProp < bProp ? -1 : 0);
});
With terrible result… can someone show me the light?
jQuery doesn’t publicly implement the
.sortmethod, it’s a hidden method because it doesn’t implement the usual jquery-like interface and is meant for internal use only. With that said, you can still use it, it hasn’t changed since it was added to the library. Try this:http://jsfiddle.net/rz5gL/