en.javascript.info/2-ui/4-forms-controls/1-form-elements/1-add-select-option/solution.md
Dmitry Anderson 1b4bd42a24
another one
2018-08-21 08:57:13 +03:00

21 lines
410 B
Markdown

The solution, step by step:
```html run
<select id="genres">
<option value="rock">Rock</option>
<option value="blues" selected>Blues</option>
</select>
<script>
// 1)
let selectedOption = genres.options[genres.selectedIndex];
alert( selectedOption.value );
// 2)
let newOption = new Option("Classic", "classic");
genres.append(newOption);
// 3)
newOption.selected = true;
</script>
```