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 trialYAWEI SONG
9,168 PointsWhy the teacher add"$newColor.click()" at the end?
i can't understand why the teacher add the line ''$newColor.click()"at the bottom. I have tried, if there is no this line, the effects works as well.
2 Answers
Jeremy Canela
Full Stack JavaScript Techdegree Graduate 30,766 PointsThe variable $newColor is assigned to the <li></li> in .controls li.
<script>
$(".controls li").click(function() {
// Execute code once this is clicked
});
$newColor = $("<li></li>"); // The variable is assigned to the <li></li>
$newColor.css(); // Changes the CSS of the li
$newColor.click(); // Triggers $(".controls li") because $newColor is assigned to the <li></li> in .controls
</script>
This Step was a little difficult and hard to explain. If you have questions please comment :)
OMER BALAK
4,255 PointsIn this way ,you can trigger to click event even .So function will be executed without any click on li item.Actually what we are trying to do is to change recently added li items border color white (class of selected) when click add new color button.