jquery use image alt text as link anchor text
Pergunta
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?
Solução
$(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);
});
});
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow