问题描述:

For example, I have:

<span class="obfuscate oxy">abc</span>

<style>.oxy::after{content:"n";}</style>

<span class="obfuscate sin">text 1<span class="a">text in span</span>text 2</span>

<style>.sin::after{content:"h";}</style>

And want it to to become like this:

n

<span class="obfuscate oxy">abc</span>

h

<span class="obfuscate sin">text 1<span class="a">text in span</span>text 2</span>

How to do with JQuery?

网友答案:

You cannot use JavaScript (or any client side library) to do this. Pseudo elements ::after and ::before are not part of the DOM and cannot be accessed with JavaScript.

One alternative would be to change the class (with different pseudo elements) of the elements.

For example:

.oxy::after{content:"n";}
.oxyb::before{content:"n";}

And then, from JS do: $('.obfuscate').removeClass('oxy').addClass('oxyb');

相关阅读:
Top