jquery在父div中选择类 [英] jquery select class inside parent div

查看:113
本文介绍了jquery在父div中选择类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改图片的替代,我点击
选择图片的类( add_answer

I'm trying to change the alt of the image, I'm clicking by selecting the image's class (add_answer)

注意: .add_answer 在不同的内容中多次显示 div

jQuery(function(){   // Add Answer

    jQuery(".add_answer").click(function(){
        var count = $(this).attr("alt");
        count++;
        $('.a_type_'+count+'').show();
        $(this).parents("div:first").$('.add_answer').attr("alt", count);
    }); 

});

此行似乎不起作用,如何选择 add_answer 类通过它的父级 div

This line doesn't seem to be working, how do I select this add_answer class by way of it's parent div

$(this).parents("div:first").$('.add_answer').attr("alt", count);

其他人有什么想法吗?

.destroy_answer时,我在尝试降低 .add_answer 图像上的 alt 值时遇到问题单击

I'm trying having trouble decreasing the alt value on the .add_answer image when .destroy_answer is clicked

jQuery(function(){   // Hide Answer

    jQuery(".destroy_answer").click(function(){
        $(this).parents("div:first").hide();
        var count = $('.add_answer').attr("alt");
        count--;
        $('.add_answer',$(this).parent('div:first')).attr('alt',count);


    }); 

});

问题专栏:

$('.add_answer',$(this).parent('div:first')).attr('alt',count);


推荐答案

您可以使用父div作为范围:

you can use the parent div as the scope:

 $('.add_answer',$(this).parent('div:first')).attr('alt',count);

这篇关于jquery在父div中选择类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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