ashish vyas
ashish vyas

Reputation: 33

How to select all siblings child together

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

Upvotes: 0

Views: 30

Answers (1)

PraveenKumar
PraveenKumar

Reputation: 1861

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>

Upvotes: 1

Related Questions