[Home] > Snippets  > Browser  > DOM  >  Check if an element is focused

Check if an element is focused

JavaScript

const hasFocus = (ele) => ele === document.activeElement

TypeScript

const hasFocus = (ele: Node): boolean => ele === document.activeElement