Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<select size="6">
  <option value="BMW">BMW</option>
  <option value="Mercedes">Mercedes</option>
  <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 change the value of the label attribute of the option-group.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
  document.getElementById("myOptgroup").label = "A Random Car Selection";
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_optgroup_label2 by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 21 Dec 2022 18:16:59 GMT -->
</html>