0

I have found posts referencing JQuery but I would like to know if it's possible to get the content string of text of a psuedo::after element on an element.

Screen shot: enter image description here

If I have the element in question selected with e.g. document.querySelectorAll('.checkout-form-error')[0];

How can I select the string of text 'Postal code field is required.' using JS?

Doug Fir
  • 19,971
  • 47
  • 169
  • 299

1 Answers1

2

This can be done by the window.getComputedStyle helper.

var str = window.getComputedStyle(document.querySelector('.mock'), ':after').getPropertyValue('content');
                  
console.log(str)
.mock::after{
  content: "we need to get this text ye?"
}
<div class="mock">

</div>
Joelgullander
  • 1,624
  • 2
  • 20
  • 46