Reputation: 227
which is the shortest and best way to sort div class by name not by alphabetic name.
Here is my Testsite:
http://devauth.labscope.de/htmlapp/report-overview_test.html
I will to sort in the content div class so:
How can i solve this? I know i can to give my class dark_red_1 but i will solve this without that.
I hope someone have idea.
Upvotes: 0
Views: 1299
Reputation: 388446
Try
var array = ['dark_red_gradient', 'red_gradient', 'orange_gradient', 'yellow_gradient', 'white_gradient'];
var $ul = $('#mytest');
var sorted = $ul.children('li').get().sort(function (o1, o2) {
return $.inArray(o1.className, array) - $.inArray(o2.className, array)
});
$.each(sorted, function () {
$(this).appendTo($ul)
});
Assuming mytest
is the id of the container li
element.
Upvotes: 1