Skip to content

Instantly share code, notes, and snippets.

@rasy-js
Created June 15, 2017 11:49
Show Gist options
  • Save rasy-js/c08dff832bd98b67041e07ce19e2d858 to your computer and use it in GitHub Desktop.
Save rasy-js/c08dff832bd98b67041e07ce19e2d858 to your computer and use it in GitHub Desktop.
removeChildOptions
function removeOptionExeptFirstAndCurrent(e) {
var select = e.target;
var selected_value = options[options.selectedIndex].value;
while(select.children[1]) {
if (select.childElementCount == 2) break;
if (select.children[1].value == selected_value) {
select.removeChild(select.children[2]);
continue;
}
select.removeChild(select.children[1]);
}
}
document.querySelector('select').addEventListener('change', removeOptionExeptFirstAndCurrent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment