I have a code that looks like this:
<div id="wrapper">
<img id="first" class="images" src="img/nike.jpg" />
<img id ="second" class = "images" src="img/golden.jpg" />
<img id = "third" class ="images" src ="img/a.jpg" />
<img id = "fourth" class="images" src="img/God__s_Canvas_by_Delacorr.jpg" />
</div>
I want to wrap each img with <a name = n>
dynamically. So my solution was to do this:
$(".images").wrap('<a></a>')
$("#wrapper a").each(function(n) {
$(this).attr('name', n);
})
Is it possible to chain the 2 statements into 1 statement? I know that jQuery is particularly do elegant chaining so I think it's definitely possible. I just don't know how to yet.