Skip to content
Advertisement

How do you apply a class’s style with setAttribute inside a class that extends HTMLElement?

I have a class that I add an element with a class name that should make the text white which I have defined in my CSS’s style, but it does not. The text remains black. How am I supposed to achieve this other than setting the element’s CSS manually?

JavaScript
JavaScript
JavaScript

Advertisement

Answer

You have added h5 element to the shadow dom so the style is not applied.

To apply the style, it is needed to define independent <style> tag inside shadow dom as follows.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement