I am just trying to write some code, for each element of a specific class i need to find a certain attribute, then replace an element. the code i have right now looks like this:
<div class="a-photo" alt="*/THE IMG SRC*/"></div>
<div class="a-photo" alt="*/THE IMG SRC*/"></div>
<div class="a-photo" alt="*/THE IMG SRC*/"></div>
<div class="a-photo" alt="*/THE IMG SRC*/"></div>
$('.a-photo').each().replaceWith(function(){
var hash = $(this).attr('alt')
"<div class='a-photo' style='background:url("+ hash +") center no-repeat;></div>"
});
i know this is not right, and its not working, but i can’t think of how to write this, any help would be greatly appreciated!
EDIT
i should mention that the amount of elements is not predetermined.
I think you want following: