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 1

oren tal
oren tal
5,738 Points

why should we deselect?

Isn't it enough just to get the certain list by writing $(this).addclass(selected") ? why is it necessary to deselect the other lists and remove them? - $(this).siblings().removeClass("selected");

1 Answer

Devron Baldwin
Devron Baldwin
3,508 Points

Think what will happen if you don't deselect the elements before selecting the correct one.

You would click an element, it selects. Everything is okay so far.

You click a different element, it selects. The last element you've clicked will still show as selected because you didn't remove the selected class from it. Now you have two elements that are selected.

At no time will you be able to deselect any elements, clicking elements will only make them selected.

By removing the selected class from all the elements and then applying the selected class to the element you've clicked on you are only allowing one element to be selected at a time.

I hope this helps.

oren tal
oren tal
5,738 Points

yap, it makes it clear. thanks :)

Devron Baldwin
Devron Baldwin
3,508 Points

No problem, happy to help!