Skip to content

Instantly share code, notes, and snippets.

@conorluddy
Last active June 29, 2016 10:09
Show Gist options
  • Save conorluddy/ff54c657fd5e379f35c7feaea5a41ed3 to your computer and use it in GitHub Desktop.
Save conorluddy/ff54c657fd5e379f35c7feaea5a41ed3 to your computer and use it in GitHub Desktop.
JS (jQuery) function to add a class to the document once the user hits the tab key. Allows you to use additional styles for accessibility that won't show until tab key has been used. Probably causes issues, use with care.
/**
* If user hits tab key then we add a class to <html> that lets us use
* additional styling hints to show focus etc.
*/
function detectTabKey() {
$(document).one('keydown', function(e) {
if (e.keyCode === 9) {
$('html').addClass('is-tab-user');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment