Skip to content Skip to sidebar Skip to footer

How To Get A Dom Element's ::before Content With Javascript?

I want to know whether it is possible to get a DOM element's ::before content, which was set by CSS3. I have tried some ways, but I still can't make it, so it's very confusing to m

Solution 1:

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>

Post a Comment for "How To Get A Dom Element's ::before Content With Javascript?"