Search code examples
javascriptdomelementdetect

Javascript: check for ::after in element


I have a very simple element:
enter image description here
How can I check if this element contains the ::after using Javascript?

(I have the element using document.getElementsByTagName('h2')[0])

I don't know how the thing works, and I don't need to know, I just need the code to see if it exists...

In some cases the element looks like this:
enter image description here
I need to be able to detect both cases, if possible!


Solution

  • Check this link, explains how to use it in plain JavaScript (might only work in newer browsers): http://davidwalsh.name/pseudo-element

    Edit: if you're looking to edit what the content of the :after is, reference this SO question: Selecting and manipulating CSS pseudo-elements such as ::before and ::after using jQuery