I have a collection of images in a div, like so:
<div class="image-container">
<img width="174" height="174" src="http://mysite.com/images/portfolio/p1.jpg" class="image-style" typeof="foaf:Image">
<img width="174" height="174" src="http://mysite.com/images/portfolio/p2.jpg" class="image-style" typeof="foaf:Image">
<img width="174" height="174" src="http://mysite.com/images/portfolio/p3.jpg" class="image-style" typeof="foaf:Image">
<img width="174" height="174" src="http://mysite.com/images/portfolio/p4.jpg" class="image-style" typeof="foaf:Image">
</div>
I would like to use jQuery to convert each image into a div and set the image as a background image, similar to this structure:
<div class="image-container">
<div style="background-image:url(http://mysite.com/images/portfolio/p1.jpg)"><span>image</span></div>
<div style="background-image:url(http://mysite.com/images/portfolio/p2.jpg)"><span>image</span></div>
<div style="background-image:url(http://mysite.com/images/portfolio/p3.jpg)"><span>image</span></div>
<div style="background-image:url(http://mysite.com/images/portfolio/p4.jpg)"><span>image</span></div>
</div>
While I can achieve this for one image, I am unsure of the best method to iterate through all the images within my parent div (image-container
) and make the necessary conversions.
Any assistance on this matter would be greatly appreciated. C