0

I need to change pseudo element (::before) style in javaScript by DOM style. How can I do that?

Like this

document.getElementById("new-store-nav").style.color= "#000";

I have changed this style by calling ID but how can I call ::before in javascript?

Shuvo
  • 25
  • 6

1 Answers1

0

You need to use getComputedStyle function which is on window object

In your case it would be like:

const color = window.getComputedStyle(
    document.getElementById("new-store-nav"), ':before'
).getPropertyValue('color')

Reference to David Walsh's site here

Dominik Matis
  • 2,086
  • 10
  • 15