Welcome to the Treehouse Community
Looking to learn something new?
Matt Schaefer6,039 Points
var color declaration question
I'm confused about how this line gets us the background-color of the "red" class, or whichever <li> initially has the "selected" tag in addition to the class for its color.
When an HTML element has two classes like in the case of "red selected" here does this mean that by getting the background-color of the selected class we are actually pulling the background-color from the red class because the <li> in question has both of those classes?
var color = $(".selected").css("background-color");
Casey Ydenberg15,622 Points
You've actually getting the color of an element, not a class. JQuery will return whatever element(s) matches the jquery selector
.selected. Then the
.css method returns the property value currently possessed by that element, irrespective of where it came from in the stylesheet or if it's inline. So the fact that the
.selected elements color was set by a different class doesn't actually matter.
Note that if your query matches more than one element,
.css will just return the property set on the first one.