Reputation: 3770
How to select all the child elements within a certain <div>
except the active one? For example:
<div>
<a id="1" class="item" href="#">Item 1 </a>
<a id="2" class="item" href="#">Item 2 </a>
<a id="3" class="item" href="#">Item 3 </a>
</div>
<script>
$(function() {
$(".item").mouseover(function() {
// HOW TO hide all the items with class item except this one
});
});
Upvotes: 0
Views: 73
Reputation: 1604
Think of it differently... Hide all, then show me:
$(function() {
$(".item").mouseover(function() {
// Hide all:
$('.item').hide();
// Show "me":
$(this).show();
});
});
Upvotes: 0
Reputation: 630607
You can use .not()
to exclude this
(the current element), like this:
$(function() {
$(".item").mouseover(function() {
$(".item").not(this).hide();
});
});
Or, if they're always siblings use .siblings()
, like this:
$(function() {
$(".item").mouseover(function() {
$(".item").siblings().hide();
});
});
Upvotes: 1