I have the following code
<ul>
<li>
<a><img src="mysource" alt="my alt tag 1"/></a>
</li>
<li>
<a><img src="mysource" alt="my alt tag 2"/></a>
</li>
<li>
<a><img src="mysource" alt="my alt tag 3"/></a>
</li>
<li>
<a><img src="mysource" alt="my alt tag 4"/></a>
</li>
</ul>
I’m trying to get the alt tag of the image. I have the position of the list item i’m trying to access saved in a variable ‘currentPos’ but I can’t get the alt content. Any help would be great. This is what i’ve tried so far
altText = $("ul li").index(currentPos).find('img').attr('alt');
Use
eqinstead ofindex:Here’s a working example.
indexreturns a number indicating the index position of the element, whereaseqactually gets the element at the specified index.