Option Label Attribute
Definition and Usage
Label
The attribute sets or returns in the dropdown list options Label Attribute Value.
The label attribute specifies a shorter version for the option, which will be displayed in the dropdown list.
See Also:
HTML Reference Manual:HTML <option> label Attribute
HTML Reference Manual:HTML <option> Tag
Example
Example 1
Change the label value of the option in the dropdown list:
document.getElementById("myOption").label = "newLabel";
Example 2
Return the label value of the option in the dropdown list:
var x = document.getElementById("myOption").label;
Example 3
Prompt the label value of the selected option in the dropdown list:
var x = document.getElementById("mySelect").selectedIndex; alert(document.getElementsByTagName("option")[x].label);
Syntax
Return the label attribute:
optionObject.label
Set the label attribute:
optionObject.label = text
Attribute Value
Value | Description |
---|---|
text | Specify a shorter version for the option. |
Technical Details
Return value: |
String value, representing the label (label) of the option in the dropdown list. 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:Cannot set label attribute in Firefox (only returns).