The main purpose of Cascading Style Sheets (CSS) is to add styles to HTML elements. However, in some cases adding additional elements to the document is redundant or impossible. In fact, there is a feature in CSS that allows us to add additional elements without disturbing the document itself, which are "pseudo-elements".
Previous words
It is not possible to directly set js effects for before and after pseudo-elements
Example
Now you need to add (:before content is "prefix", color is red pseudo-class) for (div with id as box and content as "I am test content")
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div id="box">我是测试内容</div> <script> var oBox = document.getElementById('box'); </script> </body> </html>
Solution
[Method 1] Dynamically embed CSS styles
IE8-browser treats the