In previous lessons, we accessed the select
tag to get or change the selected list item. It's
not really necessary. After all, you can directly
set the property selected
of some
option
tag to true
.
For example, let's make the list item with number two selected:
let select = document.querySelector('#select');
let option = select[2];
option.selected = true;
Given a dropdown list and a button. By clicking on the button, make selected the last item in the list.