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 trialNikola Mitic
9,023 PointsHow does $newColor.click() able to select the new color?
I have difficulty understanding how it works. I understand that handler from first click event is called, but why it's called? I found hard to understand how this two is connected.
2 Answers
Unsubscribed User
6,144 PointsSince you created this earlier :
$('.controls ul').on("click", "li", function(){
$(this).addClass('selected');
$(this).siblings().removeClass('selected');
color = $(this).css("background-color");
});
And the $newColor variable is equal to an li from this unordered list, when you trigger the click event on it, the 'selected' class will be added to it.
Byron Glover
5,772 PointsOr put even more simply, that new little colored circle your adding to the page, it will be "selected by default".
As apposed to you then having to "click" on it once you have added the newly created color option to the menu.