I am trying to get the computed style from a :before
selector of an element.
I have tried this, but it's not working, how can I make this work?
var a = window.getComputedStyle(document.querySelector('#one:before'), null);
alert(a.getPropertyValue("content"))
https://jsfiddle.net/99qe4knh/5/
According to MDN, the second parameter to the .getComputedStyle()
method is the pseudo element:
var style = window.getComputedStyle(element[, pseudoElt]);
pseudoElt (Optional) - A string specifying the pseudo-element to match. Must be omitted (or null) for regular elements.
Therefore you should use the following:
var a = window.getComputedStyle(document.querySelector('#one'), ':before');
alert(a.getPropertyValue("content"));
Updated Example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With