Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nelldnine/2ef194cfae5f691bf074a0c27b35c927 to your computer and use it in GitHub Desktop.
Save nelldnine/2ef194cfae5f691bf074a0c27b35c927 to your computer and use it in GitHub Desktop.
iOS 7 fix for not triggering select's onChange event
$.fn.quickChange = function(handler) {
return this.each(function() {
var self = this;
self.qcindex = self.selectedIndex;
var interval;
function handleChange() {
if (self.selectedIndex != self.qcindex) {
self.qcindex = self.selectedIndex;
handler.apply(self);
}
}
$(self).focus(function() {
interval = setInterval(handleChange, 100);
}).blur(function() { window.clearInterval(interval); })
.change(handleChange); //also wire the change event in case the interval technique isn't supported (chrome on android)
});
};
$('select').quickChange(function(e) {
$(this).blur();
$('select').focus(); // prevents an extra blur from firing on focus
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment