This article mainly introduces JavaScript to acquire pseudo element (Pseudo-element) attribute of method technique, this article gives the realization code directly, need friend can refer to the next
CSS pseudo Element (pseudo-elements) is very useful-you can use it to create a CSS triangle, used in the Tip box, you can also use it to do a lot of simple tasks, without the need for extra HTML elements. Previously, the CSS properties of pseudo elements were not available in JavaScript, but now there is a new JavaScript method to access them! Let's say your CSS code is like this:
The code is as follows:
. element:before {
Content: ' NEW ';
Color:rgb (255, 0, 0);
}
To get the style attributes in the. Element:before, you can use the following JavaScript code:
The code is as follows:
var color = window.getComputedStyle (
Document.queryselector ('. Element '), ': Before '
). GetPropertyValue (' Color ')
By taking the pseudo element as the second parameter of the window.getComputedStyle method, you can get the attributes in the pseudo element style! Put this technique into your knowledge base, and as the browser progresses, the artifacts will become more and more useful!