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

I don't really understand what siblings method can do

Hi, Can someone explain to me more clearly what siblings method can do.

2 Answers

Jesus Mendoza
Jesus Mendoza
23,288 Points

.siblings lets you target all the sibling elements of a specific element. Example:

Let's say you have

<ul>
   <li></li>
   <li class="clickedElement"></li>
   <li></li>
   <li></li>
</ul>

All siblings of "clickedElement" are the li inside the ul except for the "clickedElement" itself.

In the video he is using the sibling method to remove the "active" class from all the sibling elements of the clicked element and add the "active" class said element.

Tiago Aguiar
Tiago Aguiar
10,550 Points

for a better understanding, I strongly recomend the CSS Selector's course. That might clarify a bit more.