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 PointsCan someone explain me this line of code?
$newColor.css("background-color", $("#newColor").css("background-color"))
I understand that we're changing the background color of the variable $newColor, but adding the value $("#newColor").css("background-color") throws me off.
3 Answers
Jacob Mishkin
23,118 Points$newColor.css("background-color",$("#newColor").css("background-color"));
What is happening here is explained better than me in the prior video: perform part 2. He explains that the css method takes two arguments, the "getter" and the "setter" so what it is saying is get the css style background and apply it to the the id newColor background-color. I hope this makes sense. I would suggest watching the prior video as he I think explains its best.
lesak
6,260 PointsThanks Jacob. I understand it now. I think what confused me was the variable name $newColor was pretty similar to the jquery object name. All clear. Thanks!
Jacob Mishkin
23,118 PointsI agree, the var name is a little confusing. I'm glad I could help.
Jacob Mishkin
23,118 Pointsthe variable name is the jquery object, its the id name that is the same. the id name is stated with a # sign, and its the same name as the variable jquery object
john larson
16,594 Pointsoh...now I get it 0.o) $newColor is not $("#newColor")
Jacob Mishkin
23,118 PointsJohn, that is correct. This is a perfect example of why its important to clearly and properly name your variables. As we can see naming your variable the same as the id name of the div might not be the best choice, for people who are beginning to learn jQuery. So outside of knowing the difference between $newColor and #newColor, Its more important to name variables that are clear, concise, and can be easily distinguished.
lesak
6,260 PointsI just had to read that sentence a few times but I think I've digested it now. Thanks heaps.
john larson
16,594 Pointsjohn larson
16,594 PointsI think I've seen something like this in sci-fi time loop scenarios, or looking into a mirror in front of a mirror that goes on for infiniti...