X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

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;
document.getElementById("demo").innerHTML = x;

The result of x will be:

Mercedes

Try it yourself »

Example

Return 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

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook