Javascript DOM HTML Option label Property get

Introduction

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

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

Click the button to return the value of the label attribute.

View in separate window

<!DOCTYPE html>
<html>
<body>

<select size="2">
  <option id="myOption" label="c++">C++</option>
  <option label="javascript">Javascript</option>
</select>/*ww  w  .  jav  a  2s .co  m*/
<button onclick="myFunction()">Test</button>

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

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

</body>
</html>



PreviousNext

Related