开发者

jquery use image alt text as link anchor text

开发者 https://www.devze.com 2023-04-08 00:11 出处:网络
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.

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消