Skip to content

Instantly share code, notes, and snippets.

@neodigm
Last active July 15, 2020 16:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save neodigm/b8f59ab4f99ab3c34c511779f564584c to your computer and use it in GitHub Desktop.
Save neodigm/b8f59ab4f99ab3c34c511779f564584c to your computer and use it in GitHub Desktop.
JavaScript | Remove ALL positive tabIndex on the entire page | ES5 | A11y Testing
// Remove ALL tabIndex on the entire page - Thats a fun thing to do. ES5
// From the entire document remove tabIndex if its value is greater than 0
[].slice.call( document.querySelectorAll("[tabIndex]") ).filter(function(el){ // Neodigm 2020
console.log("-- | " + el.tabIndex );
if( el.tabIndex >= 1 ){
el.tabIndex = "";
}
});
// From the entire document add a tabIndex="0" attrib if an A has no href
[].slice.call( document.querySelectorAll("A") ).filter(function(el){
//console.log("== | " + el.tabIndex, el.href );
if( !el.href ){
el.tabIndex = 0;
}
});
@neodigm
Copy link
Author

neodigm commented Jun 6, 2020

TIPS:

  • Generally, do not use a tab index value greater than 0. Use tabindex="0" on an A element that does not have an href.
  • In dev tools console click on the eye icon and create this expression - document.activeElement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment