Skip to content

Instantly share code, notes, and snippets.

@michaelwhyte
Created February 8, 2018 19:03
Show Gist options
  • Select an option

  • Save michaelwhyte/32ad77c466c6a32f6d8cc8a45d897fc2 to your computer and use it in GitHub Desktop.

Select an option

Save michaelwhyte/32ad77c466c6a32f6d8cc8a45d897fc2 to your computer and use it in GitHub Desktop.
Make dropdown navigation bar keyboard accessible
const $nav = $('nav');
// The following JS modified from
// JS found at this per: http://codepen.io/laviperchik/pen/dlcBt
$.fn.accessibleDropDown = function () {
var el = $(this);
/* Make dropdown menus keyboard accessible */
el.find('a').focus(function() {
$(this).parents("li").addClass("hover");
}).blur(function() {
$(this).parents("li").removeClass("hover");
});
}
$nav.accessibleDropDown();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment