Javascript DOM HTML OptionGroup label Property set

Introduction

Change the label/description of an option-group:

document.getElementById("myOptgroup").label = "Language Selection";

Click the button to change the value of the label attribute of the option-group.

View in separate window

<!DOCTYPE html>
<html>
<body>

<select size="6">
  <option value="CSS">CSS</option>
  <option value="c++">C++</option>
  <optgroup id="myOptgroup" label="Programming Language">
    <option value="javascript">Javascript</option>
    <option value="html">HTML</option>
    <option value=""sql">SQL</option>
  </optgroup>
</select>/*from   w ww . ja va2s  . c o  m*/

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

<script>
function myFunction() {
  document.getElementById("myOptgroup").label = "A Random Car Selection";
}
</script>

</body>
</html>

The label property sets or gets the value of the label attribute of an option-group.

The label attribute sets a label/description for an option-group.

The label property accepts and returns a String type value.




PreviousNext

Related