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 trialRyan Scott
6,479 PointsConsole 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
2 Answers
Ryan Scott
6,479 PointsI 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.
Ted Sumner
Courses Plus Student 17,967 PointsThe 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
6,479 PointsYa, the single quotes don't actually change the code. I figured out what the bug was. Thanks for the quick reply!
Ted Sumner
Courses Plus Student 17,967 PointsTed Sumner
Courses Plus Student 17,967 PointsPut the language next to the top three tick marks for proper coloration.