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 trial

JavaScript jQuery Basics (2014) Creating a Simple Drawing Application Perfect

Evan Gatchell
Evan Gatchell
5,878 Points

Bug in Drawing App

Despite the red color being selected when the page loads, the color of the initial strokes are always black unless I click a color.

How do I fix?

1 Answer

Philip Enchin
seal-mask
.a{fill-rule:evenodd;}techdegree
Philip Enchin
Full Stack JavaScript Techdegree Student 24,726 Points

I did it by simulating a click on that first color:

//Simulate a click on the preselected color
$('.controls li.selected').click();

It's worth noting here that the color variable doesn't need to be initialized anymore since it will be set inside your function that's triggered by the click:

var color = $('.selected').css('background-color');

becomes

var color;