HTML | DOM OptionGroup label Property
The OptionGroup label Property in HTML DOM is used to set or return the value of the label attribute in an <optgroup> element. The label attribute is used to specify the description of a OptionGroup element.
Syntax:
- It return the optiongroup label property.
optiongroupObject.label
- It is used to set the optiongroup label Property.
optiongroupObject.label = text
Property Values: It contains single value text which specify the description of the OptGroup Element.
Example 1: This example returns the OptionGroup label property.
html
<!DOCTYPE html><html><head> <title> HTML DOM optgroup label Property </title></head><body style = "text-align:center"> <h1 style = "color: green;"> GeeksforGeeks </h1> <h2>HTML DOM optgroup label Property</h2> <select> <!--A label optgroup--> <optgroup label="Sorting Algorithms" id="GFG"> <option value="merge">Merge sort</option> <option value="quick">Quick sort</option> </optgroup> </select> <br><br> <button onclick="myGeeks()">Click Me</button> <p id="sudo" style="font-size:20px;"></p> <script> function myGeeks() { var G = document.getElementById("GFG").label; document.getElementById("sudo").innerHTML = G; } </script></body></html> |
- Before Clicking on Button:

- After Clicking on Button:

Example 2: This example sets the optgroup label property.
html
<!DOCTYPE html><html><head> <title> HTML DOM optgroup label Property </title></head><body style = "text-align:center"> <h1 style = "color: green;"> GeeksforGeeks </h1> <h2>HTML DOM optgroup label Property</h2> <select> <!--A label optgroup--> <optgroup label="Sorting Algorithms" id="GFG"> <option value="merge">Merge sort</option> <option value="quick">Quick sort</option> </optgroup> </select> <br><br> <button onclick="myGeeks()">Click Me</button> <p id="sudo" style="font-size:20px;"></p> <script> function myGeeks() { var G = document.getElementById("GFG").label = "Algorithms of DataStructures"; document.getElementById("sudo").innerHTML = G; } </script></body></html> |
- Before Clicking on Button:

- After Clicking on Button:

Supported Browsers: The browsers supported by HTML DOM OptionGroup label Property are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Safari
- Opera
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML course.



