To select siblings of an item you can use the .siblings()
method.
A typical example where you want to modify the siblings of an item is in a menu:
<ul class="menu">
<li class="selected">Home</li>
<li>Blog</li>
<li>About</li>
</ul>
When the user clicks on a menu item the selected
class should be added to the clicked element and removed from its siblings:
$(".menu").on("click", "li", function () {
$(this).addClass("selected");
$(this).siblings().removeClass("selected");
});
The method takes an optional selector
argument, which can be used if you need to narrow down the kinds of siblings you want to select:
$(this).siblings("li").removeClass("selected");