2017-08-16 37 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