<html>
<body>
<p>Click the button to create an OPTGROUP element.</p>
<button onclick="myFunction()">Try it</button>
<select id="mySelect" size="6">
<option>BMW
<option>Mercedes
<option>Ford
<option>Volvo
<option>Toyota
</select>
<script>
function myFunction() {
var x = document.getElementById("mySelect");
var y = document.createElement("OPTGROUP");
y.setAttribute("label", "SwedishCars");
y.appendChild(x.options[3])
x.insertBefore(y, x.options[3]);
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_optgroup_create by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Jan 2020 03:07:54 GMT -->
</html>