$('#newsImageGallery li').each(function() {
alert($(this));
});
私の各liには、IDを持つ画像がありますが、その画像IDを警告するにはどうすればよいですか?
$('#newsImageGallery li').each(function() {
alert($(this));
});
私の各liには、IDを持つ画像がありますが、その画像IDを警告するにはどうすればよいですか?
$('#newsImageGallery li').each(function() {
alert($(this).find("img").attr("id"));
});
またはもちろん、検索なしで:
$('#newsImageGallery li img').each(function() {
alert($(this).attr("id"));
});
そして、Pointyが以下で述べているように、jQuery 1.6以降を使用する場合は、.attrの代わりに.propを使用することをお勧めします。
$('#newsImageGallery li img').each(function() {
alert($(this).prop("id"));
});
alert( $(this).find('img').attr('id') );
これを試して:
$('#newsImageGallery li').each(function() {
alert($(this).find('img').attr('id'));
});