If your list is dependably ordered (as presented), then you can skip catching the relationship, ie first()
, etc, and follow .prevAll('optgroup')
all the way up. But if the order of your option
s might change, try .nextAll('optgroup')
, or follow @Barmar's logic to traverse in the direction needed:
$("#venue").change(function() {
$("#venue option:selected").each(function() {
if ($(this).prevAll('optgroup').attr('label') == 'International') {
alert('detected');
}
});
});