HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Option Object : Change the label value of an option in a drop-down list
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.
Property | |||||
---|---|---|---|---|---|
label | Yes | Yes | Yes | Yes | Yes |
Return the label property:
Set the label property:
Value | Description |
---|---|
text | Specifies a shorter version for the option |
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) |
---|
Return the label value of an option in a drop-down list:
var x = document.getElementById("myOption").label;
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);
HTML reference: HTML <option> label attribute
❮ Option Object