jquery - run function on each element except the one that was clicked

前端 未结 1 817
感动是毒
感动是毒 2021-01-05 09:37

As some example code, I might have something like this:

$(\'a.parent\').click(function(){

        $(\'a.parent\').each(function(){
            $(this).stop(         


        
相关标签:
1条回答
  • 2021-01-05 09:43

    you can use :not(this) so change :

     $('a.parent').each(function(){
                $(this).stop(true,false).animate({
                    width: '140px'
                },200,function(){
                });
            });
    

    to :

    $('a.parent:not('+this+')').each(function(){
                $(this).stop(true,false).animate({
                    width: '140px'
                },200,function(){
                });
            });
    

    or use .not(this) after $('a.parent') , so :

    $('a.parent').not(this).each(function(){
                    $(this).stop(true,false).animate({
                        width: '140px'
                    },200,function(){
                    });
                });
    
    0 讨论(0)
提交回复
热议问题