elementIsFocused

JavaScript, Browser

Checks if the given element is focused.

  • 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

Recommended snippets

  • hasClass

    JavaScript, Browser

    Checks if the given element has the specified class.

  • renderElement

    JavaScript, Browser

    Renders the given DOM tree in the specified DOM element.

  • getSiblings

    JavaScript, Browser

    Returns an array containing all the siblings of the given element.