I\'m trying to sort a list of divs with jQuery. Essentially the list might look like this:
var jVotes = $('div.contest_entry span.votes'), vals = [];
jVotes.each(function() {
var numVotes = $(this).html(); // may also be able to use .text()
vals.push(numVotes);
$(this).data('num-votes', numVotes);
});
vals.sort(function(a, b) {
return (a < b) ? -1 : (a > b) ? 1 : 0;
});
var jParent = $('selector for parent container');
for (var i = 0; i < jVotes.length; i++) {
jParent.append(jParent.find('[data-num-votes=' + vals[i] + ']'));
}