Option label Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Option

Description

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>
<html>
<body>

<select>
  <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>

<script>
function myFunction() {
    document.getElementById("myOption").label = "newLabel";
    document.getElementById("demo").innerHTML = "changed";
}
</script>

</body>
</html>

Related Tutorials