Response title
This is preview!




I have used the plugin to sort a list with 288 items with no noticeable change in load time. I am, however, open to any suggestions to optimize this plugin.
(function($)
{
$.sortList = function(selector)
{
var __o = {s:[],o:{}};
var sel = (selector) ? selector : 'select';
$(sel + ' option').each(function(i,v)
{
__o.s.push($(v).attr('value'));
__o.o[$(v).attr('value')] = v; });
__o.s = __o.s.sort(function(a,b)
{
return b.toLowerCase() < a.toLowerCase();
});
$(sel).html('');
$.each(__o.s,function(l,w) { $(sel).append(__o.o[w]); }); }
}(jQuery);
Usage:
$.sortList('select[name=roles]');
© 2012 jQuery Foundation
Sponsored by
and others.
