HTMLSelectElement: value property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The HTMLSelectElement.value
property contains the value of the first selected element associated with this
element.
This property can also be set directly, for example to set a default value based on some condition.
Value
Examples
Retrieving the selected value
html
js
const logElement = document.querySelector("#log");
function log(text) {
logElement.innerText = text;
}
const select = document.querySelector("#bird-select");
select.addEventListener("change", () => {
log(`Selection: ${select.value}`);
});
Specifications
Specification |
---|
HTML # dom-select-value-dev |