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.
<!DOCTYPE html> <html> <head> <title> HTML DOM optgroup label Propeerty </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="fnt-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.
<!DOCTYPE html> <html> <head> <title> HTML DOM optgroup label Propeerty </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="fnt-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
Recommended Posts:
- HTML | DOM OptionGroup disabled Property
- HTML | DOM Label htmlFor Property
- HTML | DOM Option label Property
- HTML | DOM Track label property
- HTML | DOM OptionGroup Object
- HTML | label Tag
- HTML <label> for Attribute
- HTML | DOM Label Object
- HTML | label Attribute
- HTML | aria-label attribute
- HTML | <option> label Attribute
- HTML | <optgroup> label Attribute
- HTML | <track> label Attribute
- HTML | <label> form Attribute
- How to create an HTML checkbox with a clickable label?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

