Skip to content

Instantly share code, notes, and snippets.

@stephband
Last active February 5, 2021 13:27
Show Gist options
  • Select an option

  • Save stephband/115b0307940989c79c9306ca49f95d4b to your computer and use it in GitHub Desktop.

Select an option

Save stephband/115b0307940989c79c9306ca49f95d4b to your computer and use it in GitHub Desktop.
Log activeElement on focus
document.addEventListener('focusin', (e) =>
// Sanity check for target being activeElement, should always be true
console.log('focusin', e.target === document.activeElement, document.activeElement)
);
document.addEventListener('focusout', (e) =>
// Sanity check that activeElement is body, should always be true
console.log('focusout', document.body === document.activeElement)
);
@stephband
Copy link
Author

Yes, on Chrome too.

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