Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Magdalena Misiuna
Magdalena Misiuna
11,692 Points

How to target :focus on the div and remove all styles when element is no longer in :focus state?

See below for the link with the code. When any element within Periodic Table is selected, the main info container displays more details about each selected element. How to I make this extra info div go to it's default stage when no elements within periodic table is selected? Is there a way to create if / else statement targeting :focus state of each element?


1 Answer

Steven Parker
Steven Parker
217,627 Points

Clearing a focus generates another event called "blur". You can add a listener for that event to reset the details.

And by using event delegation, just one handler could reset the details for all of the individual table elements. Note that blur doesn't bubble, but you can either set the Usecapture flag on the listener or you can use the similar event named "focusout" which does bubble.