[英]On mouse hover/unhover parent element, change url hash of children image
I have an <li>
with an <img>
inside. 我有一个
<li>
<img>
里面有一个<img>
。 I want pick each one by his class or id. 我想按他的班级或身分挑选每个人。 This
<img>
is an SVG with #black and #white versions, and his url in my HTML ends with #black as default. 此
<img>
是具有#black和#white版本的SVG,默认情况下,他在我的HTML中的网址以#black结尾。 What I need: When I hover <li>
I need that the 我需要什么:当我悬停
<li>
我需要 's url end changes from #black to #white , and when user unhover, changes again to #black . 的url结尾从#black更改为#white ,并且当用户取消悬停时,其网址再次更改为#black 。 How can I manipulate end of texts ( # at
<img url="">
in this example) in Javascript? 如何在Javascript中操纵文本结尾(在此示例中,在
<img url="">
中为# )?
Thanks in advance, and I believe that answers in this topic will help other users as well. 在此先感谢您,我相信该主题的答案也会对其他用户有所帮助。
EDIT 2: 编辑2:
(you can replace "img" with your selector if you like) (如果愿意,可以用选择器替换“ img”)
$("li.navi-item").hover(function() {
$(this).find("img").attr("src", $(this).find("img").attr("src").replace("#black", "#white"));
}, function() {
$(this).find("img").attr("src", $(this).find("img").attr("src").replace("#white", "#black"));
});
put the code inside your $(document).ready(function () { } 将代码放入$(document).ready(function(){}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.