OptionGroup label Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:OptionGroup


The label property sets or gets the label attribute of an option-group, which is the label/description for an option-group.

Set the label property with the following Values

Value Description
text Sets a label/description for the option-group

Return Value

A String, representing the label of the option-group

The following code shows how to change the label/description of an option-group:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<select size="6">
  <option value="B">B</option>
  <option value="M">M</option>
  <optgroup id="myOptgroup" label="Swedish Cars">
    <option value="css">CSS</option>
    <option value="html">HTML</option>
    <option value="sql">SQL</option>
</select>/*www. j a va 2s  .c o  m*/

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

function myFunction() {
    document.getElementById("myOptgroup").label = "Selection";


Related Tutorials