[英]Change element style CSS onclick?
I don't know why my CSS does not work here is my jsfiddle , I tried focus but when I click around even if it is not a link the effect goes away? 我不知道为什么我的CSS在这里不起作用是我的jsfiddle ,我尝试了焦点但是当我点击时即使它不是一个链接效果消失了?
<div class="footer-container">
<ul>
<li id="color"><a href="#">English(US)</a></li>
</ul>
</div>
$(document).ready(function(){
$("#color").click(function(){
$(this).css("color", "black");
});
});
By using $("#color")
you are targeting the parent of your concerned element. 通过使用
$("#color")
您将定位相关元素的父级。 Use $("#color a")
: 使用
$("#color a")
:
$(document).ready(function(){
$("#color a").click(function(){
$(this).css("color", "black");
});
});
https://jsfiddle.net/bh58c1pf/ https://jsfiddle.net/bh58c1pf/
Or you can do: 或者你可以这样做:
$(document).ready(function(){
$("#color").click(function(){
$(this).children().eq(0).css("color", "black");
});
});
But it would be slower 但它会慢一点
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.