[英]Using .css() on pseudo elements with jQuery
var navIcon1 = $('.nav-toggle span, .nav-toggle span:before, .nav-toggle span:after');
if (iconPos >= audPos && iconPos < eventPos) {
navIcon.css('color', 'black');
navIcon1.css('color', 'black');
}
I am trying to change the color of bootstrap navigation. 我试图改变引导程序导航的颜色。 I tried this code but it is not working for me.
我尝试了这段代码,但它对我不起作用。
Can I change the CSS of pseudo elements with jQuery? 我可以用jQuery更改伪元素的CSS吗?
而不是在if中添加css,为给定位置添加一个clas到“nav-toggle”并为该类添加颜色
The only one of the elements you can modify using this method is .nav-toggle span
, you could do: 您可以使用此方法修改的元素中唯一一个是
.nav-toggle span
,您可以这样做:
if (iconPos >= audPos && iconPos < eventPos) {
$(".nav-toggle span").css('color', 'black');
}
As to the other ones: :before
, :after
etc. are pseudo elements
- jQuery can't access them the way you are trying to do it. 至于其他的::
:before
, :after
等是pseudo elements
- jQuery无法以你尝试的方式访问它们。
Adding a class containing your preferred color to the elements you want to change would be a way of achieving what you want to achieve. 将包含首选颜色的类添加到要更改的元素将是实现您想要实现的目标的一种方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.