jquery use image alt text as link anchor text
Question
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 missing?
Solution
$(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);
});
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow