jquery use image alt text as link anchor text
i'm trying to use an image's alt text and use it as the text for its corresponding anchor tag.
this would be used at some point in a slide show.
this is what i have so far, but it's inserting the all text for anything other than the first image in the div. what am i missi开发者_如何学Pythonng?
Here's the jsbin example
$(document).ready(function(){
$("div img[alt^='slide']").each(function(i, item){
var imageAlt = $(item).attr("alt");
var text = "this is " + imageAlt + ".";
console.log(imageAlt);
$("ul a").eq(i).text(text);
});
});
Fiddle: http://jsfiddle.net/maniator/g33H8/1/
精彩评论