Response title
This is preview!
Description: Sorts an array of DOM elements, in place, with the duplicates removed. Note that this only works on arrays of DOM elements, not strings or numbers...... This function only works on plain JavaScript arrays of DOM elements, and is chiefly used internally by jQuery. You probably will never need to use it.
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]');EDITED
© 2013 jQuery Foundation
Sponsored by and others.