开发者

Set alt tag to more than 1000 images

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

精彩评论

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

关注公众号