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 trialJavid Abbasov
9,243 Pointswhy????
Why we used this code? i didnt get. $color = $(this).css("background-color");
2 Answers
Jacob Mishkin
23,118 Pointsthe code is used to store or cache the color. So when you click on the button you can begin to set the CSS property of background-color to the canvas. the actual drawing is using on the mouse event. Remember the "this" is referring to the click event, so on click the variable color means CSS background-color.
I hope this helps.
jcorum
71,830 PointsAs Andrew says at about 2:30, since he is selecting the current element he can use this to refer to it. Think of this as meaning my. Here he is caching the background color of the current element.