Javascript examples for DOM HTML Element:OptionGroup
The OptionGroup object represents an HTML <optgroup> element.
You can access an <optgroup> element by using getElementById():
<!DOCTYPE html> <html> <body> <select size="4"> <optgroup id="myOptgroup" label="web"> <option value="css">CSS</option> <option value="html">HTML</option> <option value="javascript">Javascript</option> </optgroup> </select>/*from w w w . j a v a 2s.c o m*/ <button onclick="myFunction()">get the label/description of the option group</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myOptgroup").label; document.getElementById("demo").innerHTML = x; } </script> </body> </html>