CSS pseudo-elements are very useful - you can use it to create CSS triangles, use them on the prompt box, and you can also use them to complete many simple tasks without unnecessary HTML elements. In the past, the CSS attributes of pseudo-elements were not available in JavaScript, but now, there is a new JavaScript method to access them! Suppose your CSS code looks like this:
The code copy is as follows:
.element:before {
content: 'NEW';
color: rgb(255, 0, 0);
}
To get the style attribute in .element:before, you can use the following JavaScript code:
The code copy 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, and you can get the properties in the pseudo-element style! Put this technique into your knowledge base, and as the browser develops, pseudo-elements will become more and more useful!