How to get a DOM element's ::before content with JavaScript?
Pass ":before"
as the second parameter to window.getComputedStyle()
:
console.log(getComputedStyle(document.querySelector('p'), ':before').getPropertyValue('content'));
p::before,p::after { content: ' Test ';}
<p>Lorem Ipsum</p>
getComputedStyle() & getPropertyValue()
getComputedStyle(document.querySelector('span.search-box'), '::after').getPropertyValue('content');