Files
30-seconds-of-code/snippets/elementIsFocused.md
2020-09-15 21:52:00 +03:00

347 B

title, tags
title tags
elementIsFocused browser,intermediate

Returns true if the given element is focused, false otherwise.

  • Use document.activeElement to determine if the given element is focused.
const elementIsFocused = el => (el === document.activeElement);
elementIsFocused(el); // true if the element is focused