2009-11-26 55 views
0

我試圖展現一個DIV並隱藏其他的div同一類,點擊一個鏈接時如何使用jQuery的:不選擇器

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

它確實表明受影響的股利,但其他divs不隱藏 - 我使用:不是以一種錯誤的方式?我用「n-child」這種方式使用它,並且工作得很好。

任何想法如何去這個將不勝感激! :)

回答

1

嘗試:not(:eq(...))

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

這在FF,但IE7似乎忽視了:沒有選擇器。 – timkl 2009-11-27 09:25:47

1

嘗試兄弟姐妹:

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