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 3

Leonard Morrison
PLUS
Leonard Morrison
Courses Plus Student 32,914 Points

I can't seem to add a new color. There seems to be something wrong with my "$newcolor.css" method.

I can't seem to add another color to the list, but there seems to something wrong with my method...

Here's the code: https://w.trhou.se/0inadcwumh

//Problem: No user interaction causes no change to application
//Solution: When user interacts cause changes appropriately
var color = $(".selected").css("background-color");
//1. When clicking on control list items
$(".controls").on("click", "li", function()
                        {
                          //Deselect sibling elements
                          $(this).siblings().removeClass("selected");
                          //Select clicked element
                          $(this).addClass("selected");
                          //Cache current color
                          color = $(this).css("background-color");

                        });



//2. When add color is pressed
$("#revealColorSelect").click(function(){
                                        changeColor();
                                        $("#colorSelect").toggle();


                                        });
  //Show color select or hide select
  function changeColor()
{
  var r = $("#red").val();
  var g = $("#green").val();
  var b = $("#blue").val();
  $("#newColor").css("background-color", "rgb(" + r + "," + g + "," + b + ")");

}

//3.When color sliders change
$("input[type=range]").change(changeColor);
  //update the new color

//4. When add color is pressed
$("#addNewColor").click(function(){
                           var $newColor = ("<li></li>");
                           $newColor.css("background-color", $("#newColor").css("background-color"));
                           $(".controls ul").append($newColor);
                           $newColor.click();
                                    });
  //Append the color is pressed ul
  //Select the new color

//5. On mouse events on the canvas
  //Draw Lines

1 Answer

Erik Nuber
Erik Nuber
20,629 Points

You are just missing a $ in the addNewColor function

  var $newColor = $("<li></li>");