最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get source of each image in div with jQuery - Stack Overflow

programmeradmin3浏览0评论

I'm trying to do a seemingly simple loop, but I keep running into issues.

I'm trying to loop through a specific div (targeted by an ID), and return the source of the two images inside of it. Here is my HTML:

<div id="container">
   <div class="row selected" id="one"><img src="onei.png"><img src="twoi.png"></div>
   <div class="row" id="two"><img src="onei1.png"><img src="twoi2.png"></div>
 </div>

And here is my loop:

function loop() {
    alert()
    $('#container row.selected img').each(function() {
        alert($(this).attr('src'))
    });
}

I can't seem to find out why this isn't working. Shouldn't this loop through each image in my targeted div and alert the source?

I'm trying to do a seemingly simple loop, but I keep running into issues.

I'm trying to loop through a specific div (targeted by an ID), and return the source of the two images inside of it. Here is my HTML:

<div id="container">
   <div class="row selected" id="one"><img src="onei.png"><img src="twoi.png"></div>
   <div class="row" id="two"><img src="onei1.png"><img src="twoi2.png"></div>
 </div>

And here is my loop:

function loop() {
    alert()
    $('#container row.selected img').each(function() {
        alert($(this).attr('src'))
    });
}

I can't seem to find out why this isn't working. Shouldn't this loop through each image in my targeted div and alert the source?

Share Improve this question asked Feb 5, 2013 at 14:26 streetlightstreetlight 5,96813 gold badges66 silver badges102 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 11

maybe something like

function loop() {
    alert()
    $('#container .row.selected img').each(function() {
        alert($(this).attr('src'))
    });
}

you forgot the . on row

Maybe you missed the point:

'#container .row.selected img'
发布评论

评论列表(0)

  1. 暂无评论