0

I need to change the content using JavaScript but the element has a ::before in the css

  • 2
    Without some code (HTML, JavaScript & CSS) & a detailed description of what you're trying to do and what's not working, we're not going to be able to help you – phuzi Mar 04 '21 at 16:23
  • This one is helpfull pls check, https://stackoverflow.com/questions/44342065/how-to-get-a-dom-elements-before-content-with-javascript you can check against any set css property using this and add condition. – Prashant Mar 04 '21 at 17:55

1 Answers1

0

I'm supposing your :before pseudo element has a property content if it's visible, so you could use the .getComputedStyle() method

let style = window.getComputedStyle(document.querySelector('#content'),':before')

then you have to check your 'content' property

var content = style.getPropertyValue("content")

and then, you could create a condition with this content value

if( content == 'something' ) {
    document.querySelector('#content').innerHTML = "your new content"
}
Pof
  • 829
  • 5
  • 20