Skip to content

Instantly share code, notes, and snippets.

@Alex1990
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save Alex1990/d0f2b7447021d9e45b2d to your computer and use it in GitHub Desktop.

Select an option

Save Alex1990/d0f2b7447021d9e45b2d to your computer and use it in GitHub Desktop.
/**
* Check if an event is supported.
* Ref: http://perfectionkills.com/detecting-event-support-without-browser-sniffing/
*/
function isEventSupported(event) {
var testEl = document.createElement('div');
var isSupported;
event = 'on' + event;
isSupported = (event in testEl);
if (!isSupported) {
testEl.setAttribute(event, 'return;');
isSupported = typeof testEl[event] === 'function';
}
testEl = null;
return isSupported;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment