开发者

Set alt tag to more than 1000 images

I have an html file with more than 1000 images/links. I need to find an efficient way to set the alt tag of each image to the Title of the 开发者_开发问答targeted link. I know some php but I thought that JavaScript would be more efficient. What do you suggest? Thanks.


Using jquery:

$('a img').each(function(i, img) {
    var title = img.parent('a').attr('title');
    img.attr('alt', title);
});

get all img tags inside an a, then set the img's alt attribute to be equal to its parent's a title.

Not tested, will probably sell your dog into slavery, YMMV, etc...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜