I have the following xml file
<gallery>
<album title="test" description="test" lgPath="/images/commphotos/">
<img src="1130975173.jpg" />
<img src="1475634985E.jpg" />
<img src="1889677107.jpg" />
<img src="1356256436.jpg" />
<img src="834682273.jpg" />
</album>
</gallery>
I've been trying to read it using jquery to get out each of the img tags. Whats the best way to do this?
With the .map() function, you can easily get all the src attributes of those imgs into a Javascript array. Of course you can use .each() also, but it is much more elegant this way.
var srcArray = $(xml).find('img').map(function () {
return this.src;
}).get();
jsFiddle Demo
In my example, .get() is used to create a simple array from the jQuery object returned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With