I've got a SELECT element whose contents (OPTION elements) get loaded via AJAX and inserted on ready and when a different SELECT is changed. Both SELECTS have two OPTION elements appended to the list of ones loaded via AJAX:
<option disabled="disabled"></option>
<option value="edit">Edit…</option>
I've got the following jQuery event binding in the on ready:
$('#theSelect').bind('change click', handleSelection);
The handleSelection()
method then intercepts the "Edit..." option being selected, switches the selection back to the previously selected option, and fires other functions that display a dialog which allows the user to edit the options in the menu. This works great in Safari & Chrome, but there's one case that doesn't work in Chrome: if there are no options to load via AJAX, so only the disabled & "Edit..." options are visible, it will not fire an event on the "Edit..." option being selected. This seems to be because, in Chrome, the "Edit..." option is selected by default (because it's the first enabled option; Safari, on the other hand, selects the disabled option because it's the first option) and it only fires change events for SELECT elements, not clicks (why I listen to both click & change), but when "Edit..." is already selected, it's not actually changing so doesn't fire an event.
So, how can I work around this? Do I need to intercept all focus events and do the dirty work to interpret what's going on? Is there a way to get Chrome to select the disabled option instead of "Edit..."?