Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Magdalena Misiuna
Magdalena Misiuna
14,726 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?

https://mhe-newtech.s3.amazonaws.com/no_name_scrum_team/mmisiuna/PT_details_ontoggle82422/p-t.html

1 Answer

Steven Parker
Steven Parker
229,644 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.