Big Paws
Big Paws

Reputation: 31

Css doesn't work for elements inserted by innerHTML

So I want to add an image in componentDidMount like this:

document.getElementById('d3_16').innerHTML = `<img src=${damsel} 
className="npcSprite" />`

Everything shows up correctly, class in inspector seems to be assigned however the styles dont apply, while other elements created normally have their styles loaded properly.

How can i fix this?

Upvotes: 0

Views: 403

Answers (1)

TryingToImprove
TryingToImprove

Reputation: 7407

You should use class instead of className since it is just plain HTML and not JSX.

Upvotes: 2

Related Questions