I have the following code - example on jsFiddle
There is one sophisticated solution that allows you to listen click events on optgroups in multiple select. The idea is listen clicks at the parent select item and calculate if user has clicked at the optgroup title.
$('#multipleSelectId').click(function(event) {
var y = event.pageY - $(this).offset().top;
var row = Math.floor((y - 4) / 15);
$(this).find('optgroup').each(function() {
if (row == 0) {
onOptgroupClick($(this));
return false;
}
row -= $(this).children().length + 1;
});
});
This approach has been tested in Chromium 30, Firefox 25, IE 9.
I don't know whether it can be applied to single selects, but with "multiple=multiple" it works like a charm.