Get the last item that had focus

There’s 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

view of Firefox inspector with console open and a request for document.activeElement. The home page link is returned.

Published by Ted

Accessibility is more than making sure images have alternate text. I work with engineers, product managers, and designers to understand how accessibility impacts the users, set realistic deadlines, and create the solutions to provide a delightful experience to all users, regardless of their physical, sensory, or cognitive ability.

Leave a comment

Your email address will not be published.