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

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -