How to select all siblings child together

31 views Asked by At

I want that if i hover on a div then add abc class in rest div

.abc{
  color:Red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
 <h2>h2</h2>
 <p>p</p>
</div>
<div>
 <h2>h2</h2>
 <p>p</p>
</div>
<div>
 <h2>h2</h2>
 <p>p</p>
</div>

I want to use jquery traversing for this code

1

There are 1 answers

0
PraveenKumar On BEST ANSWER

I guess this will help you.

$("div").hover(function() {
    $(this).siblings("div").addClass("abc");
}, function() {
    $(this).siblings("div").removeClass("abc");
});
.abc{
  color:Red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
 <h2>h2</h2>
 <p>p</p>
</div>
<div>
 <h2>h2</h2>
 <p>p</p>
</div>
<div>
 <h2>h2</h2>
 <p>p</p>
</div>