Created
June 15, 2017 11:49
-
-
Save rasy-js/c08dff832bd98b67041e07ce19e2d858 to your computer and use it in GitHub Desktop.
removeChildOptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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