jQuery从嵌套类中检索元素 [英] jQuery retrieve elements from nested classes

查看:87
本文介绍了jQuery从嵌套类中检索元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这部分html:

<div class="ThirdRowBanner">
    <div class="yCmsComponent col-xs-12">
        <div class="simple-banner-component simple-banner">
            <img title="sometitle" alt="somealt" src="someurl/apparel-category-banner.jpg">
        </div>
    </div>
</div>

如何使用jQuery img标题,alt和src元素进行检索? 我无法在img中添加ID或其他标签.我只能从"ThirdRowBanner"类开始.

How can I retrieve with jQuery img title, alt and src elements? I can't add ids or other tag to the img. I can only start from the "ThirdRowBanner" class.

推荐答案

您可以在该类中使用.find:

$("div.ThirdRowBanner").find("img").each(function() {
    console.log($(this).attr("title")); 
    console.log($(this).attr("src")); 
    console.log($(this).attr("alt")); 
});

这篇关于jQuery从嵌套类中检索元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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