Archive for February, 2011

Re-Ordering select list elements with jQuery

February 21st, 2011

So, I came across an interesting development problem.  I was embedding a ‘select’ list from a 3rd party web service, and I wanted to re-order the items shown.  More specifically, I wanted the most commonly selected elements to be at the top of the list.  Because I couldn’t access the raw HTML, directly changing the order was not an option.  jQuery to the rescue!  Here’s a small snippet I came up with that did just the trick:

$('option[value='myVal']').detach().prepend('select.mySelect');

Viola!  Way easy!