2013-10-01 46 views
-1

這怎麼可能?繼建設不起作用:除了在jQuery中是否有類似的東西?

$('.multibutton').click(function(event) { 

    //.. some stuff before 

    $(this).next('.menu').slideDown("slow"); 

    // hide all other menus except this.next.menu 
    $('.menu :not(this.next)').hide(); 

    //.. some stuff after 
}); 

謝謝

+1

的方法是...擊鼓聲請... ['。不是()'](http://api.jquery.com/not/) – JJJ

+0

你能解釋一下你正在試圖做的是什麼?僞代碼不是很有幫助。 –

+0

@Juhana:請在評論前查看代碼.. – Gabriel

回答

1
$('.multibutton').click(function(event) { 

    //.. some stuff before 

    var elem = $(this).next('.menu').slideDown("slow"); 

    // hide all other menus except this.next.menu 
    $('.menu').not(elem).hide(); 

    //.. some stuff after 
}); 
+0

試圖..不幸的是不工作這裏是代碼現在在線:http://jsfiddle.net/fhN3H/1/ – Gabriel

+1

@ user2819288 - 這是假設是什麼?在全球範圍內,'this'是'window',它沒有下一個'menu'? – adeneo

+0

這是你要做的 - > http://jsfiddle.net/fhN3H/3/ – adeneo

0

嘗試使用jQuery.not()函數來獲取元素列表不包括規定的項目:

$('.multibutton').click(function(event) { 

    //.. some stuff before 

    $(this).next('.menu').slideDown("slow"); 

    // hide all other menus except this.next.menu 
    $('.menu').not($(this).next()).hide(); 

    //.. some stuff after 
}); 

有關jQuery.not()的更多信息。

+0

試圖..不幸的是不工作在這裏是代碼現在在線:http://jsfiddle.net/fhN3H/1/ – Gabriel

相關問題