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?

Here's the jsbin example

Was it helpful?

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);
  });
});

Fiddle: http://jsfiddle.net/maniator/g33H8/1/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top