Get OptionGroup Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:OptionGroup


The OptionGroup object represents an HTML <optgroup> element.

You can access an <optgroup> element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<select size="4">
  <optgroup id="myOptgroup" label="web">
    <option value="css">CSS</option>
    <option value="html">HTML</option>
    <option value="javascript">Javascript</option>
</select>/*www  .j  a  v  a 2  s . c  o  m*/

<button onclick="myFunction()">get the label/description of the option group</button>

<p id="demo"></p>

function myFunction() {
    var x = document.getElementById("myOptgroup").label;
    document.getElementById("demo").innerHTML = x;


Related Tutorials