Track element focus (original) (raw)

Track element focus

Kayce Basques

Suppose that you're testing the keyboard navigation accessibility of a page. When navigating the page with the Tab key, the focus ring sometimes disappears because the element that has focus is hidden. To track the focused element in DevTools:

  1. Open the Console.
  2. Click Create Live Expression Create Live Expression.
    Creating a Live Expression.
    For more information, see Watch JavaScript values in real-time with Live Expressions.
  3. Type document.activeElement.
  4. Click outside of the Live Expression UI to save.

The value that you see below document.activeElement is the result of the expression. Since that expression always represents the focused element, you now have a way to always keep track of which element has focus.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2018-12-14 UTC.