Reputation: 27628
How do I fade out all the images inside the class bMenu that are not #b2 with jQuery? Thanks.
<div class="bMenu" id="b1"><img src='b1.jpg'></div>
<div class="bMenu" id="b2"><img src='b2.jpg'></div>
<div class="bMenu" id="b3"><img src='b3.jpg'></div>
Upvotes: 2
Views: 146
Reputation: 13984
Try this:
#('.bMenu > img').each(function(it){
if(it.attr('id') != 'b2'){
it.fadeOut();
}
});
Might be a way to do it with pure selectors but this should work.
Added Later:
Ok, I went and did a test... here is what I came up with:
$('div[id!=b2].bMenu > img').each(function(){
$(this).fadeOut();
});
This selector will return two images, not the one with b2.
Upvotes: 0
Reputation: 268344
Get it all done at once with chaining:
$("#b2 img").show().parent().siblings(".bMenu").find("img").fadeOut();
Upvotes: 1
Reputation: 106332
Literal answer:
$(".bMenuL:not(#b2) img").fadeOut();
Assuming you want to make sure that the #b2 img
is shown as well:
$("#b2 img").fadeIn();
Upvotes: 2