Objeto de opción HTML DOM
Objeto de opción
El objeto Option representa un elemento HTML <option>.
Acceder a un objeto de opción
Puede acceder a un elemento <option> usando getElementById():
Ejemplo
var x = document.getElementById("myOption");
Sugerencia: también puede acceder a un objeto Opción buscando en la colección de elementos de un formulario o en la colección de opciones de una lista desplegable.
Crear un objeto de opción
Puedes crear un elemento <option> usando el método document.createElement():
Ejemplo
var x = document.createElement("OPTION");
Propiedades del objeto de opción
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 |
Propiedades y eventos estándar
El objeto Option también admite las propiedades y eventos estándar .
páginas relacionadas
Referencia HTML: etiqueta HTML <opción>