usertest
usertest

Reputation: 27628

Fading images in jQuery

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

Answers (5)

cjstehno
cjstehno

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

Sampson
Sampson

Reputation: 268344

Get it all done at once with chaining:

$("#b2 img").show().parent().siblings(".bMenu").find("img").fadeOut();

Upvotes: 1

rosscj2533
rosscj2533

Reputation: 9323

Try

$('.bMenu:not(#b2) img').fadeOut('slow');

Upvotes: 1

gnarf
gnarf

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

Per H
Per H

Reputation: 1542

$('img', '.bMenu:not(#b2)').fadeOut();

Upvotes: 1

Related Questions