I have an empty select component with a fixed width that has options added to it by Javascript. It uses a scrollbar by default. When the page loads, this element isn't quite the right height. When an option is added, the select element resizes to the correct height and stays that way until the page is reloaded or the list of options cleared. Is there a way I can make the selector load at the correct height without initializing it with an option?
function addOpt() {
let selector = document.getElementById("selector");
let opt = document.createElement("option");
opt.innerHTML = "New option";
selector.appendChild(opt);
}
<select size="8" style="width: 250px;" id="selector">
</select>
<br /><br />
<button type="button" onclick="addOpt()">Click me</button>