Is there something like except in jQuery?

前端 未结 2 454
广开言路
广开言路 2021-01-29 09:47

How is this possible? Following construction does not work:

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

    //.. some stuff before

    $(this).next(\'.menu\').         


        
相关标签:
2条回答
  • 2021-01-29 10:29

    Try using the jQuery.not() function to get a list of the elements not including the items specified :

    $('.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
    });
    

    More information on jQuery.not().

    0 讨论(0)
  • 2021-01-29 10:42
    $('.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 讨论(0)
提交回复
热议问题