Skip to content

Instantly share code, notes, and snippets.

@kentcdodds
Created July 26, 2018 13:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kentcdodds/121cd18ef58b0b22873247d29a664cb9 to your computer and use it in GitHub Desktop.
Save kentcdodds/121cd18ef58b0b22873247d29a664cb9 to your computer and use it in GitHub Desktop.

This will log the currently active element as it changes. Really great for accessibility testing when you're trying to figure out what element has focus (so you can either prevent it from getting focus or make the fact that it has focus more visually obvious for example).

javascript:(function(){if(window._activeElInterval){clearInterval(window._activeElInterval);delete window._activeElInterval;}else{var activeEl;window._activeElInterval=setInterval(function(){var currentActiveEl=document.activeElement;if(currentActiveEl!==activeEl){activeEl=currentActiveEl;console.log(activeEl);}},200);}})();
(function() {
if (window._activeElInterval) {
clearInterval(window._activeElInterval);
delete window._activeElInterval;
} else {
var activeEl;
window._activeElInterval = setInterval(function() {
var currentActiveEl = document.activeElement;
if (currentActiveEl !== activeEl) {
activeEl = currentActiveEl;
console.log(activeEl);
}
}, 200);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment