Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Interactive Web Pages with JavaScript Traversing and Manipulating the DOM with JavaScript Perform: Changing Classes

Mayur Pande
PLUS
Mayur Pande
Courses Plus Student 11,711 Points

why do we toggle after the conditional?

Bit confused on why we toggle after the if statement? I would've thought we would toggle after the condition is set, and then toggle?

1 Answer

Owa Aquino
Owa Aquino
19,277 Points

Hi Mayur,

In the video, Andrew is creating a function named editTask in which he can add to the "Edit" button to add a class of .editMode in the parent <li> of that task item. He added toggle function so if he clicked the "Edit" button he'll be able to add and remove that class (.editMode).

If you check the CSS of that project he's using the .editMode class to style the task item. So if the task <li> has the .editMode class then some elements will be shown (in this case the <input> element).

Hope this clarify your question.

Best Regards,

Owa