I'm having an issue with this.. is the value gets added but only the first h2 tag. What am I missing?
Thanks
My goal is to grab the value of the h2 tag and add the value to the image as an alt and title tag.
Below is my HTML and JS. Here is my jsFiddle File.
HTML
<ul class="list">
<li>
<img title="Product" src="/img.jpg" />
<h2>Blue</h2>
</li>
<li>
<img title="Product" src="/img.jpg" />
<h2>Red</h2>
</li>
<li>
<img title="Product" src="/img.jpg" />
<h2>Yellow</h2>
</li>
</ul>
JS
var imageID = $('.list').find('h2').html();
$("img").attr('title', imageID + ' Product');