How can I get all the product images src attributes and store them into an array?
I tried this:
var imgDetails = new Array();
imgDetails = $('.prod img').attr('src');
imgDetails[i] = $('.prod img').attr('src');
I think I need a loop but I'm not sure how to get the length of how many images they are. I know the length but didn't want to hardcode it incase I add more. I am trying to target all the images which comes from my database. (when they are retrieved, I give them a class of 'pos') I thought doing this I could target them with jquery using the class I'm just not sure on the functions of jquery and how to retrieve all the images. Using the second code everytime I click the alert box off, it pops up with another but displays this:
i know to use the
to get the value but how do I initially get the images and loop the src into the array?
Can I give them any naming convention as a way to target them for example:
<img name="0" />
<img name="1" />
<img name="2" />
<img name="3" />
<img name="nth" />
Then when I use the loop I can also grab that value and use the
variable to iterate through them?
Any hints you can give me?
EDIT: Awesome, just looked at the each() function on the jquery api and it's alerting me the src values.