This is my html:
<select id="categoryg">
<optgroup label="Main" value="binding">
<optgroup label="Sub" value="binding">
<option value="46">Test</option>
<option value="47">Test2</option>
<option value="48">Test3</option>
</optgroup>
</select>
Whenever I change the selection I want to get the label text of the parent option group “Main”.
At the moment my code just gets the label text of the sub parent option group “Sub”.
This is my code (JSFiddle):
$('select').change(function () {
var opt = $(this).find(':selected');
var sel = opt.text();
var og = opt.closest('optgroup').attr('label');
console.log(og) // Sub, should get Main;
});

