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 2

Jaspal Singh
Jaspal Singh
13,525 Points

color span is not updating after changing the sliders

Hi

i want to change to the color span background as per the input values, but it could not work. when i try to see the values of rgb in the console it is showing me the result as rgba(0,0,0,0)

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

//when clicking on control list items $('.controls li').click(function(){

//deselct the siblings $(this).siblings().removeClass('selected'); //select the clicked $(this).addClass('selected'); color = $(this).css('background-color'); });

//when new color is pressed. $('#revealColorSelect').click(function(){

//show color select span or hide the color select $('#colorSelect').toggle('slow');

});

//when color slider change. $('input[type=range]').change(function(){

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

//when add color button is clicked. //append the new color to the controls list //select the new color.

//on mouse events on the canvas. // draw lines.

2 Answers

Steven Parker
Steven Parker
231,275 Points

You have an inconsistent quote style on the line that sets the color. This creates a string using the variable names instead of substituting the values in the variables:

$('#newColor').css('background-color', 'rgb(" + r + "," + g + "," + b + " )');  // original line
$("#newColor").css("background-color", "rgb(" + r + "," + g + "," + b + " )");  // quotes fixed
Jaspal Singh
Jaspal Singh
13,525 Points

thanks Parker for your help