Element is focused

JavaScript, Browser · Oct 19, 2020

Checks if the given element is focused.

const elementIsFocused = el => (el === document.activeElement);
elementIsFocused(el); // true if the element is focused

Written by Angelos Chalaris

I'm Angelos Chalaris, a JavaScript software engineer, based in Athens, Greece. The best snippets from my coding adventures are published here to help others learn to code.

If you want to keep in touch, follow me on GitHub.

More like this

  • JavaScript DOM Querying

    Learn how to query the DOM quickly and efficiently with this collection of JavaScript tips and tricks.

    Collection · 15 snippets

  • Check if browser tab is focused

    Checks if the browser tab of the page is focused.

    JavaScript, Browser · Oct 20, 2020

  • Array to HTML list

    Converts the given array elements into <li> tags and appends them to the list of the given id.

    JavaScript, Browser · Oct 20, 2020

  • Check if HTML element has class

    Checks if the given element has the specified class.

    JavaScript, Browser · Oct 19, 2020