Option defaultSelected attribute
Definition and Usage
defaultSelected
attribute returns selected attribute the default value.
If the default selected option is selected, this property returns true
, otherwise return false
.
Note:If an option is selected by default, it is displayed first in the dropdown list.
See also:
HTML Reference Manual:Etiqueta <option> do HTML
Example
Check if the selected option is selected by default:
var x = document.getElementById("mySelect").selectedIndex; var y = document.getElementsByTagName("option"); alert("Is " + y[x].text + " selected by default? " + y[x].defaultSelected);
Sintaxe
optionObject.defaultSelected
Detalhes técnicos
Retorno: | Booleano, se a opção padrão for selecionada, retorna true; caso contrário, retorna false. |
---|
Suporte ao navegador
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Suporte | Suporte | Suporte | Suporte | Suporte |