diff --git a/snippets/elementIsFocused.md b/snippets/elementIsFocused.md new file mode 100644 index 000000000..b42d37bd4 --- /dev/null +++ b/snippets/elementIsFocused.md @@ -0,0 +1,16 @@ +--- +title: elementIsFocused +tags: browser,intermediate +--- + +Returns `true` if the given element is focused, `false` otherwise. + +Use `document.activeElement` to determine if the given element is focused. + +```js +const elementIsFocused = el => (el === document.activeElement); +``` + +```js +elementIsFocused(el); // true if the element is focused +```