This works to set a specific <option>
as the currently selected item in a <select>
:
var l = document.getElementById("list");
for (var i = 0; i < 100; i++) {
l.innerHTML += "<option value='" + i + "'>" + i + "</option>";
}
l.value = 17;
#list { width: 100px; }
<select id="list" multiple size=10>
</select>
But the item is selected at the end, which is not always the desired UI/UX.
Question: How to make that the selected item appears in the middle of the listview, or, alternatively, on top of the listview?
(if possible of course, e.g. if there are enough subsequent items).