Skip to content

Instantly share code, notes, and snippets.

@matijs
Forked from icaaq/gist:3235454
Created August 2, 2012 13:24
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 matijs/3237085 to your computer and use it in GitHub Desktop.
Save matijs/3237085 to your computer and use it in GitHub Desktop.
triggers click on spacebar key
/*
MDN: using the button role https://developer.mozilla.org/en/Accessibility/ARIA/ARIA_Techniques/Using_the_button_role
-----
Warning: Be careful when marking up links with the button role. Buttons are expected to be triggered using the Space key,
while links are expected to be triggered through the Enter key. In other words, when links are used to behave like buttons,
adding role="button" alone is not sufficient. It will also be necessary to add a key event handler that listens for the
Space key in order to be consistent with native buttons.
-----
*/
$('body').on('keypress','[role="button"]', function(e){
if(e.which === 32){
e.preventDefault();
$(this).trigger('click');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment