THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Option label Property

Option Object Reference Option Object

Example

Change the label value of an option in a drop-down list:

document.getElementById("myOption").label = "newLabel";
Try it Yourself »

Definition and Usage

The label property sets or returns the value of the label attribute in an option in a drop-down list.

The label attribute specifies a shorter version of an option.

The shorter version will be displayed in the drop-down list.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The label property is supported in all major browsers.


Syntax

Return the label property:

optionObject.label

Set the label property:

optionObject.label=text

Property Values

Value Description
text Specifies a shorter version for the option

Technical Details

Return Value: A String, representing the label of the option in the drop-down list. If the label attribute is not specified, it will return the <option> element's text content instead (same as the text property)

More Examples

Example

Return the label value of an option in a drop-down list:

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

The result of x will be:

Mercedes
Try it Yourself »

Example

Alert the label value of the selected option in a drop-down list:

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

Related Pages

HTML reference: HTML <option> label attribute


Option Object Reference Option Object