Skip to content

Instantly share code, notes, and snippets.

@Rijen
Created November 16, 2015 04:41
Show Gist options
  • Save Rijen/4acfabdb00f91198c032 to your computer and use it in GitHub Desktop.
Save Rijen/4acfabdb00f91198c032 to your computer and use it in GitHub Desktop.
var options = $('select#routeNumber option');
var arr = options.map(function (_, o) {
return {t: $(o).text(), v: o.value, r:$(o).prop('-data-role'),n:$(o).prop('-data-name')};
}).get();
arr.sort(function (o1, o2) {
return parseInt(o1.t) > parseInt(o2.t) ? 1 : parseInt(o1.t) < parseInt(o2.t) ? -1 : 0;
});
options.each(function (i, o) {
o.value = arr[i].v;
$(o).text(arr[i].t);
$(o).prop('-data-role',arr[i].r);
$(o).prop('-data-name',arr[i].n);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment