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 an OptionGroup element.
Syntax:
- It returns 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 specifies 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;" > w3wiki </ 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 = "myBeginner()" >Click Me</ button > < p id = "sudo" style = "font-size:20px;" ></ p > < script > function myBeginner() { let G = document.getElementById("GFG").label; document.getElementById("sudo").innerHTML = G; } </ script > </ body > </ html > |
Output:
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;" > w3wiki </ 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 = "myBeginner()" >Click Me</ button > < p id = "sudo" style = "font-size:20px;" ></ p > < script > function myBeginner() { let G = document.getElementById("GFG").label = "Algorithms of DataStructures"; document.getElementById("sudo").innerHTML = G; } </ script > </ body > </ html > |
Output:
Supported Browsers: The browsers supported by HTML DOM OptionGroup label Property are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Safari
- Opera