Skip to content

Instantly share code, notes, and snippets.

@guillaumecabanel
Created April 29, 2020 11:52
Show Gist options
  • Save guillaumecabanel/0b70b847056a87207ef5295c162b40da to your computer and use it in GitHub Desktop.
Save guillaumecabanel/0b70b847056a87207ef5295c162b40da to your computer and use it in GitHub Desktop.
JS | How to get selected option
const select = document.querySelector('select');
const valueFromSelectedOption = select.options[select.selectedIndex].value;
console.log(valueFromSelectedOption); // => "2"
<select>
<option value="1">test1</option>
<option value="2" selected="selected">test2</option>
<option value="3">test3</option>
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment