DOM Properties
HTMLSelectElement.selectedIndex
Read/write. Returns the zero-based index of the first selected option or -1 when none is selected. Assigning an index selects that option and deselects the others; -1 clears selection. Example result: B.
Formal Syntax & Structure
html syntaxhtml
element.selectedIndexReturn Value
number
Property value. Read/write.
Working Example
Example Snippethtml
<select id="demo"> <option>A</option> <option>B</option></select><p> Result: <output id="result"></output></p><script> const e = document.getElementById('demo'); const result = value => { document.getElementById("result").textContent = String(value); }; e.selectedIndex=1; result(e.value);</script>