Reputation: 24061
$('#newsImageGallery li').each(function() {
alert($(this));
});
In each of my li I have an image with an id, how can I alert that images id?
Upvotes: 0
Views: 240
Reputation: 125
Try this:
$('#newsImageGallery li').each(function() {
alert($(this).find('img').attr('id'));
});
Upvotes: 1
Reputation: 39532
$('#newsImageGallery li').each(function() {
alert($(this).find("img").attr("id"));
});
or of course, without the find:
$('#newsImageGallery li img').each(function() {
alert($(this).attr("id"));
});
And as Pointy mentions underneath, if you use jQuery 1.6+ you're better off using .prop instead of .attr:
$('#newsImageGallery li img').each(function() {
alert($(this).prop("id"));
});
Upvotes: 3