SMRTR ProgrammingAug 14, 2025Go Make Things

Checking for focus in an element using CSS in your JavaScript

SMRTR summary

Modern CSS selectors now offer a simpler way to check for focused elements than traditional JavaScript methods. When building dropdown menus, you can use :focus-within or :has() with :not() to close open elements without disrupting user focus. This approach makes code more readable and efficient when handling keyboard navigation and click events.

SMRTR provides this summary for quick context. The original article belongs to Go Make Things.

Read the original article
SMRTR Programming

Get the next batch of curated summaries in your inbox.

This archive is built from SMRTR newsletter summaries. Subscribe for hand-picked stories without the extra noise.