Get offsetLeft pseudo-elements using javascript

Is there a way to get offsetLeft of a pseudo element using only javascript?

I can check the :: before element through the chrome devtools console and get its offsetLeft.

As window.getComputedStyle (elem, ': before') gives the computed for :: before styles, is there anything similar to offsetLeft access?

+4
source share
1 answer

Yes, you can get the computed style for the pseudo-element, then get the left value of its bounding box:

parseInt(window.getComputedStyle(elem, ':before').getBoundingClientRect().left, 10);
+1
source

All Articles