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 trialJames Barrett
13,253 PointsWhy are we calling the changeColor() function after the click event?
Hi there.
In this code snippet:
$("#revealColorSelect").click(function(){
// changeColor();
$("#colorSelect").toggle();
});
Why are we calling the changeColor() function? I have tested it without doing this and everything still works fine.
Thanks, James.
3 Answers
Youssef Girgeis
iOS Development Techdegree Student 10,996 PointsHi James,
Yes you are right, we are calling the function changeColor() inside the first click event to set an initial rgb value. if you try to comment that line out you wont see the black color when you click the new color button, since you didnt initialize the rgb value.
James Barrett
13,253 PointsHi Juliette,
Thanks for your answer. I am still a little confused as to why we have to call the changeColor() function. It seems as if the purpose of that anonymous function is to toggle the #colorSelect and nothing else?
Thanks, James. :)
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 PointsHi James,
As far as I can see (without having watched the accompanying video/tutorial in months) the changeColor() function is only storing the values of the rgb values. There is no event attached to that function. In order to see the input new rgb values you have to either call it (the changeColor function) or place it inside of an event handler in order to see/call the new values.
Does that make sense?
Cheers:-)
James Barrett
13,253 PointsHi Juliette,
I think I understand now; was just overthinking it. From what I see... It seems as if it just sets an initital rgb value for the user to view.
Please correct me if I am wrong. :P Thanks, James.
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 Points"It seems as if it just sets an initital rgb value for the user to view."
What sets the value, changeColor() or the click event anonymous function?
One sets the value via user input and the other displays the results on click:-)
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 PointsJuliette Tworsey
Front End Web Development Techdegree Graduate 32,425 PointsHi James,
I'm posting all of the app.js code here for perspective:
Without having re-watched this video for some time now, the changeColor() function is grabbing and storing the (color) values that are chosen by the user via the sliders/inputs. You need to then call this function within your click function event in order to reveal/see the changes that you are then going to toggle.
I hope that helps!
Cheers:-)