Option label eigenschap

Definitie en gebruik

label Eigenschap instellen of teruggeven in de opties van de keuzelijst Label-eigenschap waarde.

De label-eigenschap bepaalt een korte versie voor de optie, deze korte versie wordt weergegeven in de keuzelijst.

Zie ook:

HTML referentiemanual:HTML <option> label attribute

HTML referentiemanual:HTML <option> tag

Voorbeeld

Voorbeeld 1

Wijzig de labelwaarde van de optie in de keuzelijst:

document.getElementById("myOption").label = "newLabel";

Probeer het zelf

Voorbeeld 2

Geef de labelwaarde van de optie in de keuzelijst terug:

var x = document.getElementById("myOption").label;

Probeer het zelf

Voorbeeld 3

Geef de labelwaarde van de geselecteerde optie in de keuzelijst:

var x = document.getElementById("mySelect").selectedIndex;
alert(document.getElementsByTagName("option")[x].label);

Probeer het zelf

Syntax

Geef de label-eigenschap terug:

optionObject.label

Stel de label-eigenschap in:

optionObject.label = text

Eigenschapswaarde

Waarde Beschrijving
text Stel een korte versie in voor de optie.

Technische details

Return value:

String value, representing the label of the option in the drop-down list (label).

If the label attribute is not specified, it will return the text content of the <option> element (the same as the text attribute).

Browser support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support

Note:The label attribute cannot be set in Firefox (only returned).