Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h3>A demonstration of how to access an OPTGROUP element</h3>
<select size="4">
  <optgroup id="myOptgroup" label="Swedish Cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="koenigsegg">Koenigsegg</option>
  </optgroup>
</select>
<p>Click the button to get the label/description of the option group.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
  var x = document.getElementById("myOptgroup").label;
  document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>