This article describes how to use JavaScript to obtain the attributes of a Pseudo-Element. This article provides the implementation code. For more information, see pseudo-elements in CSS) very useful-you can use it to create CSS triangles and use them in the prompt box. you can also use it to complete many simple tasks without the need for additional HTML elements. Previously, the CSS attributes of pseudo elements could not be obtained using JavaScript, but now, a new JavaScript method can be used to access them! Suppose your CSS code is like this:
The code is as follows:
. Element: before {
Content: 'New ';
Color: rgb (255, 0, 0 );
}
To obtain the style attributes in. element: before, you can use the following JavaScript code:
The code is as follows:
Var color = window. getComputedStyle (
Document. querySelector ('. element'),': before'
). GetPropertyValue ('color ')
Use the pseudo element as the second parameter of the window. getComputedStyle method. you can obtain the attributes in the pseudo element style! Put this technique into your knowledge base. with the development of browsers, pseudo elements will become more and more useful!