Sort the div in alphabetical order using data attribute
You can use String.prototype.localeCompare
JSFIDDLE here
var alphabeticallyOrderedDivs = $('.value').sort(function(a, b) {
return String.prototype.localeCompare.call($(a).data('site').toLowerCase(), $(b).data('site').toLowerCase());
});
var container = $("#aphaOrder");
container.detach().empty().append(alphabeticallyOrderedDivs);
$('body').append(container);
This should work:-
$("#aphaOrder .value").sort(function (a, b) {
if ( ($(a).attr("data-site").toLowerCase() > $(b).attr("data-site").toLowerCase()) ) {
return 1;
} else if ( ($(a).attr("data-site").toLowerCase() == $(b).attr("data-site").toLowerCase()) ){
return 0;
} else {
return -1;
}
}).each(function () {
var elem = $(this);
elem.remove();
$(elem).appendTo("#aphaOrder");
});
http://jsfiddle.net/0bs5mu6e/2/