Open In App

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:  



optiongroupObject.label
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.  






<!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() {
            let G = document.getElementById("GFG").label;
            document.getElementById("sudo").innerHTML = G;
        }
    </script>
</body>
 
</html>

Output:

 

Example 2: This example sets the optgroup label property. 




<!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() {
            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: 


Article Tags :