Add elementIsFocused
This commit is contained in:
16
snippets/elementIsFocused.md
Normal file
16
snippets/elementIsFocused.md
Normal file
@ -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
|
||||
```
|
||||
Reference in New Issue
Block a user