我有以下 HTML ..
<div class = "thumbnail">
<img src = "somePath">
</div>
<div class = "thumbnail">
<img src = "somePath">
</div>
<div class = "thumbnail">
<img src = "somePath">
</div>
<div class = "thumbnail">
<a href = "someLink"><img src = "somePath"></a>
</div>
<div class = "thumbnail">
<a href = "someLink"><img src = "somePath"></a>
</div>
我想在div.thumbnail的第一个孩子下迭代img标签。我想过滤掉它们。我用作..
var i =0;
$("div.thumbnail :first-child").each(function() {
console.log("Touch "+(++i)+" time(s) !");
if($(this).context.nodeName.toLowerCase() == 'img') {
console.log("Getting Image Tag.");
}
});
我的问题是我想过滤获取元素..
$("div.thumbnail :first-child :img").each(function(){});
我不想迭代为div.thumbnail的计数。我想迭代为第一个子标签的div.thumbnail计数是img。如何弄清楚?