Get OptionGroup Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:OptionGroup

Introduction

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

Related Tutorials