简体   繁体   English

使用jQuery切换伪元素

[英]Toggle a pseudo-element using jQuery

I am trying to toggle the display of an :after pseudo-element (ie.to show/hide it) using jQuery. 我试图使用jQuery切换一个:after伪元素(即显示/隐藏它)的显示。 I successfully toggled the display of a div, but want to do this now with :after . 我成功地切换了div的显示,但是现在想要用:after

The :after is being used to create the arrow on the box. :after用于在盒子上创建箭头。

My attempt can be seen here: http://jsfiddle.net/beechboy707/7um9knxt/1/ 我的尝试可以在这里看到: http//jsfiddle.net/beechboy707/7um9knxt/1/

Here is an extract from it showing the jQuery which is supposed to relate to the CSS selector: 以下是它的摘录,显示了应该与CSS选择器相关的jQuery:

$("#supportus-button-1").click(function () {
$(".supportus-button:after").toggle();
});

I think the easiest approach here is to use CSS classes to limit the scope where the :after rule is applied: 我认为这里最简单的方法是使用CSS类来限制应用: :after规则的范围:

.supportus-button:not(.clicked):after { ... }

Here's an updated fiddle: http://jsfiddle.net/jjcwqjLw/ 这是一个更新的小提琴: http//jsfiddle.net/jjcwqjLw/

All current browsers support the :not CSS feature: support is the same as for the :after pseudoelement. 所有当前浏览器都支持:not CSS功能:支持与:after伪元素:after 相同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM