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 triallesak
6,260 PointsWhy are the siblings deselected first in the click function before the class "selected" is added to the clicked element?
Trying to understand the structure of the function.
3 Answers
Steven Parker
231,275 PointsThe "selected" class gives the element a unique visual appearance. It is removed from the siblings of the clicked item so that only the clicked item will have the special look.
Otherwise, as you click on the different elements, eventually each one would get the special look and they would all look the same.
Why not temporarily comment out the line that clears the siblings and try it out?
lesak
6,260 PointsGood idea. Thanks for your helpful answer.
docgunthrop
12,445 PointsIn this particular example, the order does not matter, as the CSS styling change occurs instantaneously (thanks to modern computer processing power). If you put the line that adds the "selected" class to the clicked list item before the line that removes that class from the sibling list items, you'll see that it makes no difference.
If you want to see a difference in the sequence of changes, you can add a timeout.