jQuery选择器:我单击的地方里面的引用类: [英] jquery selector: reference class inside of where i clicked:

查看:77
本文介绍了jQuery选择器:我单击的地方里面的引用类:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个html:

<div class="title"><img class="arrow" src="rightarrow.gif" />Title</div>

我有此点击事件:

    $(document).ready(function () {
        $('.title').live('click', function () {

            //NEED SOMETHING HERE TO CHANGE SOURCE                 
            $(".arrow").attr("src", "downarrow.gif");
        });
    });

如您所见,我想更改图像的src属性.我上面的选择器起作用了,但是页面上还有其他类为="arrow"的项目,所以我需要一种选择该实例的方法.

as you can see i want to change the src attribute of the image. my selector above works, but there are other items on the page with class ="arrow", so i need a way to just select this one instance.

推荐答案

使用 .find() 进行约束选择器,仅查找被单击的元素中包含的元素(用$(this)表示):

$(document).ready(function() {
    $('.title').live('click', function() {
        $(this).find('.arrow').attr('src', 'downarrow.gif');
    });
});

这篇关于jQuery选择器:我单击的地方里面的引用类:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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