Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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属性的所有图像。)

  ask by Mona Coder translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
370 views
Welcome To Ask or Share your Answers For Others

1 Answer

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 ,请更正。)

JSFiddle Demo(JSFiddle演示)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...