[英]Targeting <img> by alt attribute in jQuery
I am working on the following code.我正在处理以下代码。 I want to find out why I am not able to target the
<img>
tag which only has the "award logos" alt
我想知道为什么我无法定位只有“奖励徽标”
alt
的<img>
标签
<img src="http://www.....jpg" alt="award logos">
<img src="http://www.....jpg" alt="Ranking">
<script>
$(document).ready(function() {
$('img [alt="award logos"]').wrap("<a href='http://google.com' </a>");
});
</script>
Technically, what I want to do is targeting all the images that has the specific alt attributes.从技术上讲,我想要做的是针对所有具有特定 alt 属性的图像。
Remove space between img
and [alt="award logos"]
because of the space it is looking for child element of img
with attribute [alt="award logos"]
.删除
img
和[alt="award logos"]
之间的空间,因为它正在寻找具有属性[alt="award logos"]
的img
子元素的空间。
$(document).ready(function() {
$('img[alt="award logos"]').wrap("<a href='http://google.com'> </a>");
});
NOTE - you missed >
for a
(anchor) tag while wrapping img
, please correct it.注-你错过
>
的a
,而包装(锚)标签img
,请更正。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.