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 Perform: Part 5

i can add new color but cannot use that to draw

hi there. can you help me with my code- issue. all other function like drawing is working, but when i add new color, i cannot use that color to draw, my pen only work with 3 main color code : https://w.trhou.se/hsd4x01yz2 thank you very much

1 Answer

Steven Parker
Steven Parker
229,732 Points

It doesn't look like there is any code to give the new color a click event handler. That should be done before "Select the new color".

So you could add code to do it there, but another approach would be to convert the click handler already being added to the other colors into a delegated handler. That would make it work with both the current colors and any added later.

You could do that by changing one line:

//when clicking on control list items
// $(".controls li").click(function() {           <- change this line
$(".controls ul").on("click", "li", function() {  // to this instead