Skip to content

Instantly share code, notes, and snippets.

@vishaltelangre
Created March 18, 2013 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishaltelangre/5186497 to your computer and use it in GitHub Desktop.
Save vishaltelangre/5186497 to your computer and use it in GitHub Desktop.
/*
* TL;DR => Safari Select Box onchange Event Bug Fix
* Problem:
On keyboard event of select box (like searching for desired options),
safari doesn't fire the event even hitting enter key. Instead, it fires
the change event on again hitting enter key or clicking anywhere,
so as we can get the selected option's value. Same happen when clicking
on desired option. This is weird.
*/
if(navigator.userAgent.match(/safari/i)){
$('select').keyup(function(e){
e.preventDefault();
var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
if(key == 13){
$(this).trigger('change');
}
}).click(function(e){
$(this).trigger('change');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment