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 3

Why 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
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jeremy Canela
Full Stack JavaScript Techdegree Graduate 30,766 Points

The 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 :)

In 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.