Skip to content

Instantly share code, notes, and snippets.

@dziku86
Forked from jonsage/getAllFocusableElements.js
Created August 6, 2021 18:27
Show Gist options
  • Save dziku86/9b7015992a83f5caa923f4f551200909 to your computer and use it in GitHub Desktop.
Save dziku86/9b7015992a83f5caa923f4f551200909 to your computer and use it in GitHub Desktop.
const getAllFocusableElements = (parent) => Array.from(parent.querySelectorAll('*')).filter(elm => elm.tabIndex > -1).sort((a,b) => a.tabIndex > b.tabIndex ? 1 : a.tabIndex < b.tabIndex ? -1 : 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment