Skip to content

Instantly share code, notes, and snippets.

@amitkumar
Created March 15, 2016 19:14
Show Gist options
  • Save amitkumar/9e07be8e3872ec165cd9 to your computer and use it in GitHub Desktop.
Save amitkumar/9e07be8e3872ec165cd9 to your computer and use it in GitHub Desktop.
/**
* Disable or enable focus on all focusable elements. Useful for proper keyboard navigation
* of slide-based interfaces where certain slides are hidden/shown based on user interaction.
* Assumes jQuery.
*
* @param {jQuery object} $el - jQuery object whose children will be toggled
* @param {bool} enable
* /
var toggleFocusableElements = function($el, enable){
if (enable){
$el.find('input,button,a,[role="button"],[role="checkbox"],[tabindex]').attr('tabindex', '0');
} else {
$el.find('input,button,a,[role="button"],[role="checkbox"],[tabindex]').attr('tabindex', '-1');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment