選択コントロールで現在選択されているオプションの optgroup ラベルの値を見つけようとしています。以下は、私が何をしようとしているのかを示すHTMLです。
<select id='sector_select' name='sector_select' data-placeholder="Select Sector..." style="width:200px;" class="chzn-select">
<option value='' selected='selected'>All Sectors</a>
<optgroup label="Consultancy Services">
<option value='Employment placement/ recruitment'>Employment placement/ recruitment</option>
</optgroup>
<optgroup label="Supplies">
<option value='Food, beverages and related products'>Food, beverages and related products</option>
</optgroup>
</select>
<script type="text/javascript">
$('#sector_select').change(function ()
{
var label=$('sector_select :selected').parent().attr('label');
console.log(label);
});
</script>
上記のコードは、オプション以外の選択要素の読み取り親であるため、未定義になります。何か案は?