简体   繁体   English

如何使用jQuery添加/删除:课后到div

[英]how to add / Remove :after class to div using jQuery

How to can we add/Remove :after class to div using jQuery 我们如何使用jQuery向div添加/删除:after类

let say I have following class 可以说我有以下课程

.vignetteC1:after { ... }
.vignetteC2:after { ... }
.vignetteC3:after { ... }
.vignetteC4:after { ... }
.vignetteC5:after { ... }

if we want to add after class to a dive using jQuery how can we do so. 如果我们想在课后使用jQuery进行潜水,我们该怎么做。 ?

I have googled a lot but I am only getting an example of .after function and so on. 我已经用谷歌搜索了很多,但是我只是得到一个.after函数的例子,等等。

I have tried the following but it not working 我尝试了以下方法,但无法正常工作

var VignetteVal = 'vignetteC' + value + ':after';

for (var i = 1; i <= 5; i++) {
  Img.parent().removeClass(('vignetteC' + i + ':after'));
}

Img.parent().addClass(VignetteVal);

But the above code add vignetteC2: after class to div like 但是上面的代码在类之后添加了vignetteC2:到div之类

<div class="vignetteC2: after">

You are very confused about what :after is. 您对:after是什么感到非常困惑。 It's a pseudo-element. 这是一个伪元素。 It is NOT a class and not part of the DOM structure so it cannot be edited or added with javascript. 它不是类,也不是DOM结构的一部分,因此无法用javascript编辑或添加。

Read more here > https://www.w3schools.com/css/css_pseudo_elements.asp 在此处了解更多信息> https://www.w3schools.com/css/css_pseudo_elements.asp

:after pseudo-element adds content after the content of an element. :after伪元素将内容添加到元素的内容之后。 It is not a class. 这不是一堂课。 To add content after an element you can use insertAfter() or you can use append to add content at the end of the current element. 要在元素之后添加内容,可以使用insertAfter() ,也可以使用append在当前元素的末尾添加内容。 Also, there is an after() method 另外,还有一个after()方法

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

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