Option label Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option


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

Set the label property with the following Values

Value Description
text Sets a shorter version for the option

Return Value

A String, representing the label of the option in the drop-down list.

The following code shows how to change the label value of an option in a drop-down list:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

  <option label="c">cc</option>
  <option id="myOption" label="d">dd</option>
</select>/*  w  w  w  .  jav a2 s.com*/

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {
    document.getElementById("myOption").label = "newLabel";
    document.getElementById("demo").innerHTML = "changed";


Related Tutorials