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 trialmebula
4,931 PointsColor Span Not Updating Until I Toggle Sliders
Sorry if the question title is confusing! My JS code is below. It works pretty much the same as Andrew's does in the video, however when I first click the "new color" button, the span to the left of the sliders doesn't show anything. Once I move the sliders around, it gets updated, but upon the initial popup of it, it doesn't show anything. In the video, Andrew's automatically shows up as black.
Does anybody know how to fix this? Thanks!
var color = $(".selected").css("background-color");
$(".controls li").click(function() {
$(this).siblings().removeClass("selected");
$(this).addClass("selected");
color = $(this).css("background-color");
});
$("#revealColorSelect").click(function() {
$("#colorSelect").toggle();
});
function changeColor() {
var r = $("#red").val();
var g = $("#green").val();
var b = $("#blue").val();
$("#newColor").css("background-color", "rgb(" + r + "," + g + "," + b + ")");
}
$("input[type=range]").change(changeColor);
1 Answer
Steven Parker
231,269 PointsYou missed a modification in the video.
near the end of the video this problem is addressed by adding a line:
$("#revealColorSelect").click(function() {
changeColor(): // <-- this line gets added
$("#colorSelect").toggle();
});
Also, if I remember correctly, I found the color picker much more fun to use when I made this modification to the last line:
$("input[type=range]").on("input", changeColor);