Objeto de opção HTML DOM
Objeto de opção
O objeto Option representa um elemento HTML <option>.
Acessar um objeto de opção
Você pode acessar um elemento <option> usando getElementById():
Exemplo
var x = document.getElementById("myOption");
Dica: Você também pode acessar um objeto Option pesquisando na coleção de elementos de um formulário ou na coleção de opções de uma lista suspensa.
Criar um objeto de opção
Você pode criar um elemento <option> usando o método document.createElement():
Exemplo
var x = document.createElement("OPTION");
Propriedades do objeto de opção
Property | Description |
---|---|
defaultSelected | Returns the default value of the selected attribute |
disabled | Sets or returns whether an option is disabled, or not |
form | Returns a reference to the form that contains the option |
index | Sets or returns the index position of an option in a drop-down list |
label | Sets or returns the value of the label attribute of an option in a drop-down list |
selected | Sets or returns the selected state of an option |
text | Sets or returns the text of an option |
value | Sets or returns the value of an option to be sent to the server |
Propriedades e eventos padrão
O objeto Option também suporta as propriedades e eventos padrão .
Páginas relacionadas
Referência HTML: tag HTML <option>