javascript - Loop through a list and get an elements image id? -
$('#newsimagegallery li').each(function() { alert($(this)); });
in each of li have image id, how can alert images id?
$('#newsimagegallery li').each(function() { alert($(this).find("img").attr("id")); });
or of course, without find:
$('#newsimagegallery li img').each(function() { alert($(this).attr("id")); });
and pointy mentions underneath, if use jquery 1.6+ you're better off using .prop instead of .attr:
$('#newsimagegallery li img').each(function() { alert($(this).prop("id")); });
Comments
Post a Comment