Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move an item up/down a select

I'm wondering if it's possible to change the order of things in a select control without having to totally rebuild it?

Is there a javascript function where I can change the "index" of a specific option in the select?

Thanks

like image 248
AndrewC Avatar asked Mar 10 '10 18:03

AndrewC


1 Answers

Sure, just find the two elements in jQuery (by their IDs or whatever), so you have two objects and then use before() on them

var o1=$("#opt1");
var o2=$("#opt2");
o2.insertBefore(o1);
like image 71
naivists Avatar answered Oct 04 '22 16:10

naivists