2017-08-16 61 views
-2

检索元素我有HTML的这一部分:从jQuery的嵌套类

<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”类开始。

+2

你试过'$( 'ThirdRowBanner ')找到(' IMG')' – tech2017

回答

0

您可以使用.find从该类:

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

谢谢!!!!!! – sharkbait