获取超链接的ALT属性的属性值 [英] Get an attributes value of the ALT attribute of a hyperlink

查看:92
本文介绍了获取超链接的ALT属性的属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的a-tag(链接)包含innerHTML,它是这样的图像:

My a-tag (link) contains innerHTML which is an image like this:

.innerHTML = <img alt="hello world" src="/Content/Images/test.png">

如何使用JQuery获取alt属性的文本?

How can I get the text of the alt attribute with JQuery?

推荐答案

成为$a您的<a/>元素.

您可以使用jQuery:

Using jQuery you can do:

$("img", $a).first().attr("alt");


或者,使用纯JavaScript:


Or, using pure JavaScript:

var $img = $a.getElementsByTagName("img")[0];
console.log($img.alt);

在此处查看.

这篇关于获取超链接的ALT属性的属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆