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 trialRiya Chatterjee
7,582 PointsColor does not add to the row of colors
When I make a new color and try to add it, it does not add. I have refreshed my browser and reviewed my code several times. Can anyone help? My Code:
//Problem: No user interaction causes no change to application
//Solution: When user interacts cause changes appropiately
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 element
color = $(this).css("background-color");
});
//When "new color" is pressed
$("#revealColorSelect").click(function() {
//Show color select or hide the color select
changeColor();
$("#colorSelect").toggle();
});
//Update the new color span
function changeColor() {
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();
//Select the new color
$newColor.click();
});
//On mouse events on the canvas
//Draw lines
1 Answer
rydavim
18,814 PointsLooks like you haven't passed a parameter into append
. Remember that you need to tell it what it should be appending.
$(".controls ul").append($newColor); // Don't forget to specify $newColor as the parameter.
That should do it, but let me know if you have any questions. Happy coding! :)
rydavim
18,814 Pointsrydavim
18,814 PointsI've added some formatting and syntax highlighting to your code. You can do this using the following markdown: