jQuery-在除单击的元素之外的每个元素上运行功能 [英] jquery - run function on each element except the one that was clicked

查看:69
本文介绍了jQuery-在除单击的元素之外的每个元素上运行功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一些示例代码,我可能会有类似的内容:

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

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

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

        $(this).animate({
            width: '160px'
        },200,function(){
        });

    });

问题是我不希望被单击的元素设置为140px的宽度,然后再恢复为160px的动画.

The problem is that I don't want the element that was clicked to animate to 140px width and then back to 160px.

是否有一种方法可以仅对集合中未被单击的元素执行每个"操作?还是有更好的方法?

Is there a way to run 'each' on only the elements in a set who were not clicked? Or is there a better way?

推荐答案

您可以使用:not(this),所以请更改:

you can use :not(this) so change :

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

至:

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

或在$('a.parent')之后使用.not(this),所以:

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

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

这篇关于jQuery-在除单击的元素之外的每个元素上运行功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆