Sélectionner un objet HTML DOM
Sélectionner un objet
L'objet Select représente un élément HTML <select>.
Accéder à un objet sélectionné
Vous pouvez accéder à un élément <select> en utilisant getElementById() :
Exemple
var x = document.getElementById("mySelect");
Astuce : Vous pouvez également accéder à un objet Select en effectuant une recherche dans la collection d' éléments d'un formulaire.
Créer un objet de sélection
Vous pouvez créer un élément <select> en utilisant la méthode document.createElement() :
Exemple
var x = document.createElement("SELECT");
Sélectionner les collections d'objets
Collection | Description |
---|---|
options | Returns a collection of all the options in a drop-down list |
Sélectionnez les propriétés de l'objet
Property | Description |
---|---|
autofocus | Sets or returns whether a drop-down list should automatically get focus when the page loads |
disabled | Sets or returns whether the drop-down list is disabled, or not |
form | Returns a reference to the form that contains the drop-down list |
length | Returns the number of <option> elements in a drop-down list |
multiple | Sets or returns whether more than one option can be selected from the drop-down list |
name | Sets or returns the value of the name attribute of a drop-down list |
selectedIndex | Sets or returns the index of the selected option in a drop-down list |
size | Sets or returns the value of the size of a drop-down list |
type | Returns which type of form element a drop-down list is |
value | Sets or returns the value of the selected option in a drop-down list |
Sélectionner les méthodes d'objet
Method | Description |
---|---|
add() | Adds an option to a drop-down list |
checkValidity() | |
remove() | Removes an option from a drop-down list |
Propriétés et événements standard
L'objet Select prend également en charge les propriétés et les événements standard .
Pages connexes
Tutoriel HTML : Formulaires HTML
Référence HTML : balise HTML <select>