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 trialHossam Khalifa
17,200 Pointsdon't understand this cache color line
$(".controls li").click(function(){
//deselect sibiling element
$(this).siblings().removeClass("selected");
//select clicked element
$(this).addClass("selected");
//cache current color
color= $(this).css("background-color");
});
I don't understand what this cache current color line does and why it should be written
2 Answers
James Andrews
7,245 Pointscolor = $(this).css("background-color");
when you click a list item that is a child of an element classed "controls" it will do this in this order.
1) remove the "selected" class from all other list item elements, 2) it will then add the selected class to the list item element that was just clicked. 3) It will then ask the clicked element what it's background-color css is and store it in the variable color and do nothing with it (unless there's more code).
If you were to add an alert(color); underneath that line you'd see the value of the background-color alerted.
Hossam Khalifa
17,200 PointsThank you
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsMarked as best answer
David Harris
6,009 PointsDavid Harris
6,009 PointsThis is the answer I needed to understand what was going on. Thank you so much for this thorough and clear response.