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.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


  • Before Clicking on Button:
  • After Clicking on Button:

Example 2: This example sets the optgroup label property.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


  • 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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.