Alex Rivera | Logout

jQuery get img source attributes from list and push into array

Asked 2010-03-01T10:08:07.240
20

I have this thumbnail list and would like push the image paths (sources) into an array: tn_array

<ul id="thumbnails">
    <li><img src="somepath/tn/004.jpg" alt="fourth caption" /></a></li>
    <li><img src="somepath/tn/005.jpg" alt="fifth caption" /></a></li>
    <li><img src="somepath/tn/006.jpg" alt="sixth caption" /></a></li>
</ul>
Edit
Report

1 Answer

5

You can loop through ever img element:

var tn_array = Array();

$('#thumbnails img').each(function() {
    tn_array.push($(this).attr('src'));
});
answered 2010-03-01T10:13:09.113

Your Answer