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 trialMasa Mune
Courses Plus Student 4,794 Pointsi 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
231,275 PointsIt 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