Blog

I’ve been using Milanuncios to look for places to rent or buy, but for some reason their drop-down menu isn’t ordered alphabetically. Which is a bit annoying when you are looking for a specific area (i.e. Bogatell) but it could be anywhere in the list of a 100…

So, here’s a script to re-order any list.

var my_options = $("#zona option");
my_options.sort(function(a,b) {
  if (a.text > b.text) return 1;
  else if (a.text < b.text) return -1;
  else return 0
});
$("#zona").empty().append(my_options);

You should change #zona to whatever id the <select> element is.