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


Modure Rares
Modure Rares
Courses Plus Student 9,041 Points

jQuery Color Selector

I made a color changing div with the rgb values from the inputs but I dont know why the color of the div does not changes unless i release the mouse

function changeColor(){

      var r = $("#red").val();
      var g = $("#green").val();
      var b = $("#blue").val();
      $("#selectedColor").css("background-color", "rgb(" + r + "," + g + "," + b + ")");
Modure Rares
Modure Rares
Courses Plus Student 9,041 Points

red #green and #blue are the inputs with a type of range

2 Answers

Steven Parker
Steven Parker
229,967 Points

The change event fires only after the change is complete.

In this case, that would be when you release the mouse button. If you would prefer to handle every alteration of the input value as it happens, use the input event instead:

$("input[type=range]").on("input", changeColor);

Every in your code looks good unless when when you triggered some mouse events that you never included in the code in the forum