Skip to content

Instantly share code, notes, and snippets.

@imjakechapman
Created April 2, 2014 23:22
Show Gist options
  • Save imjakechapman/9945290 to your computer and use it in GitHub Desktop.
Save imjakechapman/9945290 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
});
@Favorwilliams
Copy link

My Pleasure to write you,
My name is Favor Williams,
My email address is
( Favor24@live.com)
Am interested to know
more about you,
Contact me for my
photo and other
important issue via,

Favor24@live.com

@mikehdt
Copy link

mikehdt commented Aug 24, 2015

I've run across an issue with this where it causes Firefox (both OS X and Windows) to erroneously close the options when the select is triggered. It may be worthwhile restricting this logic to only apply if being viewed on an iOS device (this probably means UA sniffing though, which may be less desirable long-term).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment