Skip to content

Instantly share code, notes, and snippets.

@3emad
Created April 2, 2012 18:12
Show Gist options
  • Save 3emad/2285936 to your computer and use it in GitHub Desktop.
Save 3emad/2285936 to your computer and use it in GitHub Desktop.
Changing options position pitfall
/*
* // the following example failed to keep the last index.
*
* temp = selElem.options[0];
* selElem.options[0] = selElem.options[1];
* selElem.options[1] = temp
* return;
*/
var dash = selElem.options[0];
var all = selElem.options[1];
selElem.options[0] = new Option(all.value, all.innerHTML);
selElem.options[1] = new Option(dash.value, dash.innerHTML);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment