Created
October 23, 2013 05:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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