开发者

Fading images in jQuery

How do I fade out all the images inside the class bMenu that are not #b2 with jQuery? Th开发者_运维技巧anks.

<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>


Literal answer:

$(".bMenuL:not(#b2) img").fadeOut();

Assuming you want to make sure that the #b2 img is shown as well:

$("#b2 img").fadeIn();


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


Try

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


Get it all done at once with chaining:

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜