Skip to content

::Last-Child – Ted Drake

Accessibility | Inclusion | Belonging | DEI AF

Get the last item that had focus

Summary

Learn how to use the browser’s console tab to find the last item to have focus.

This post was restored from the Wayback Machine. It was originally published on September 20, 2019

There are a lot of times when you need to find out which item on a page has focus. This is especially tricky when controlling focus as you move in and out of modals and components. Here’s how you can get the object with focus on a web page.

  1. Open inspector and choose the console tab.
  2. Type: document.activeElement

This will return the element that currently has focus