Skip to content

Instantly share code, notes, and snippets.

@jaydenseric
Created October 23, 2013 05:39
Show Gist options
  • Save jaydenseric/7113093 to your computer and use it in GitHub Desktop.
Save jaydenseric/7113093 to your computer and use it in GitHub Desktop.
How to make a custom jQuery `activate` event. This is useful for UI elements that can be activated by mouse click or using the enter key for keyboard accessibility.
$(document).ready(function() {
$(document).on('click keypress', function(event) {
if (event.type == 'click' || event.which == 13) {
$(event.target).trigger('activate');
}
});
$("button").on('activate', function() {
alert('Button activated!');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment