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 02 Answers
Reset to default 11maybe 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'