如何使用jQuery:not选择器

如何使用jQuery:not选择器,jquery,Jquery,我试图在单击链接时显示一个div并隐藏具有相同类的其他div $(this).find('h2 a').click(function() { $('.expand-collapse:eq(' + numberFix + ')' ).show('fast'); $('.expand-collapse:eq:not(' + numberFix + ')' ).hide('fast'); return false; }); 它确实显示了受影响的div,但其他div没有隐藏-我是否使用

我试图在单击链接时显示一个div并隐藏具有相同类的其他div

$(this).find('h2 a').click(function() {
    $('.expand-collapse:eq(' + numberFix + ')' ).show('fast');
    $('.expand-collapse:eq:not(' + numberFix + ')' ).hide('fast');
return false;
});
它确实显示了受影响的div,但其他div没有隐藏-我是否使用了:没有错误的方式?我在“第n个孩子”中这样使用,效果很好

任何关于如何进行此操作的想法都将不胜感激!:)

试试
:不(:eq(…)

试试兄弟姐妹:

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