jQuery: order list items but keep classes

I have a list with classes eg:\[code\] <ul id="my_list"> <li class="notrelevant"><a href="http://stackoverflow.com/questions/14536912/#1">something not relevant</a></li> <li class="notrelevant"><a href="http://stackoverflow.com/questions/14536912/#2">something not relevant</a></li> <li class="notrelevant"><a href="http://stackoverflow.com/questions/14536912/#3">something not relevant</a></li> <li class="notrelevant"><a href="http://stackoverflow.com/questions/14536912/#4">something not relevant</a></li> <li class="notrelevant"><a href="http://stackoverflow.com/questions/14536912/#5">something not relevant</a></li> <li class="relevant"><a href="http://stackoverflow.com/questions/14536912/#75">something not relevant</a></li></ul>\[/code\]U can see that te last class of the list is relevant and this class should always be on the end of the list!I try to order the list randomly with this:\[code\]$(document).ready(function(){ var liArr =[] $('ul').each(function(){ var $ul = $(this); liArr = $ul.children('li'); }); var i = liArr.length, j, temp; while (--i) { j = Math.floor(Math.random() * (i + 1)); temp = liArr; liArr = liArr[j]; liArr[j] = temp; };$('ul').append(liArr); });\[/code\]And ofc is sortet to somewhere in the middle.I dont want to ignore the last item, all tags have to be sorted randomly.How can i order the list randomly and set only the last class to "relevant", or can i only oder the tag?
 
Back
Top