Toggle a pseudo-element using jQuery

微笑、不失礼 提交于 2019-12-13 12:21:58

问题


I am trying to toggle the display of an :after pseudo-element (ie.to show/hide it) using jQuery. I successfully toggled the display of a div, but want to do this now with :after.

The :after is being used to create the arrow on the box.

My attempt can be seen here: http://jsfiddle.net/beechboy707/7um9knxt/1/

Here is an extract from it showing the jQuery which is supposed to relate to the CSS selector:

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

回答1:


I think the easiest approach here is to use CSS classes to limit the scope where the :after rule is applied:

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

Here's an updated fiddle: http://jsfiddle.net/jjcwqjLw/

All current browsers support the :not CSS feature: support is the same as for the :after pseudoelement.



来源:https://stackoverflow.com/questions/25470641/toggle-a-pseudo-element-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!