Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript jQuery Basics (2014) Creating a Simple Drawing Application Perform: Part 3

Ryan Scott
Ryan Scott
6,479 Points

Console error message: $newColor.css is not a function. Help?!

What am I doing wrong to make the console tell me that $newColor.css (it's near the bottom of the code) is not a function. It should be running .css("background-color", $("#newColor").css("background-color")) on $newColor, as I declared it as a variable right above, right?

//Problem: No user interaction causes no change to application
//Solution: When user interacts cause changes appropriately

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

//When clicking on control list items
$(".controls li").click(function(){

  //Deselect sibling elements
  $(this).siblings().removeClass("selected");

  //Select clicked element
  $(this).addClass("selected")

  //Cache current color here
  color = $(this).css("background-color"); 

});

//When new color is pressed
$("#revealColorSelect").click(function(){

  //Show color select or hide the color select
  changeColor();
  $("#colorSelect").toggle();

});

function changeColor() {

  //Update the new color span
  var r = $("#red").val();
  var g = $("#green").val();
  var b = $("#blue").val();
  $("#newColor").css("background-color", "rgb(" + r + "," + g + "," + b + ")");

}

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

//When add color is pressed
$("#addNewColor").click(function(){

  //Append the color to the controls ul
  var $newColor = ('<li></li>');
  $newColor.css("background-color", $("#newColor").css("background-color"));
  $(".controls ul").append($newColor);

  //Select the new color
  $newColor.click();

  //Deselect sibling color

});

//On mouse events on the canvas
  //Draw lines

Put the language next to the top three tick marks for proper coloration.

2 Answers

Ryan Scott
Ryan Scott
6,479 Points

I figured it out by combing through the instructor's code on the video. I left out the $ before the <li> tags, so when it put the variable in elsewhere, it made that line of code not work. These little things are kicking my butt.

The only thing that I see is that you use single quotes around

<li></li>. 

I don't remember if that matters in JavaScript. It does change the formatting of the post, so something is happening.

Ryan Scott
Ryan Scott
6,479 Points

Ya, the single quotes don't actually change the code. I figured out what the bug was. Thanks for the quick reply!