开发者

How to use the jQuery :not selector

开发者 https://www.devze.com 2022-12-12 20:32 出处:网络
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() {

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

精彩评论

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