开发者

How to use the jQuery :not selector

I'm trying to show one div and hide other divs with the same class, when a link is clicked

$(this).find('h2 a').click(function() {
    $('.expand-collapse:eq(' + numberFix + ')' ).show('fast');
    $('.expand-collapse:eq:not(' + numberFix + ')' ).hide('fast');
return false;
});

It does show the affected div, but the other divs do开发者_开发技巧n't hide - am I using :not in a wrong way? I used it this way with "nth-child" and that worked fine.

Any ideas on how to go about this would be appreciated! :)


Try :not(:eq(...)).

$(this).find('h2 a').click(function() {
    $('.expand-collapse:eq(' + numberFix + ')' ).show('fast');
    $('.expand-collapse:not(:eq(' + numberFix + '))' ).hide('fast');
    return false;
});


Try siblings:

$(this).find('h2 a').click(function(e) {
    $('.expand-collapse:eq(' + numberFix + ')' )
        .show('fast').siblings().hide('fast');
    e.preventDefault();
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜