I have table structure with the following.
<td class="backgroundimage"><img src="02.jpg" border="0" class="foregroundimage"></td>
<td class="backgroundimage"><img src="03.jpg" border="0" class="foregroundimage"></td>
I am trying to get each img src within my table by doing this.
$('.backgroundImage').each(function(index){
var oldImage = $(this).next("img").attr('src');
alert(oldImage);
});
This alerts undefined. What have I done wrong? Am I using .next() wrong?
Yes –
.next()looks at the next sibling. And none of yourtdelements have animgsibling.You probably wanted to use
$(this).find('img')or simply$('img', this).Depending on what you need to do the following might also do the job: