Files
30-seconds-of-code/snippets/elementIsFocused.md
Angelos Chalaris c41b58c590 Add elementIsFocused
2020-08-07 15:21:27 +03:00

345 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