Return the label/description of an option-group:
var x = document.getElementById("myOptgroup").label;
Click the button to return the value of the label attribute of the option-group.
<!DOCTYPE html> <html> <body> <select size="6"> <option value="CSS">CSS</option> <option value="c++">C++</option> <optgroup id="myOptgroup" label="Programming Language"> <option value="javascript">Javascript</option> <option value="html">HTML</option> <option value=""sql">SQL</option> </optgroup> </select>//w ww . j a v a 2s . com <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myOptgroup").label; document.getElementById("demo").innerHTML = x; } </script> </body> </html>