0

For some reason the css doesnt apply to this:

document.write('<p ' + 'class="' + txtClassName + '">' + txtValue + "</p>");

And when I go into inspect, it shows this:

<p class="txt">Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>

If I put that exact line into the original html file, the css works.

Anyone know why this is?

Tobias H.
  • 426
  • 1
  • 6
  • 18
  • 1
    When exactly is the `document.write` executed? – Teemu Dec 07 '20 at 13:48
  • 1
    Long story short: don't use `document.write()`. – Ivar Dec 07 '20 at 13:51
  • I tested the code and it worked. Where is the ```document.write``` placed? I don't know if your scenario forces ```document.write``` but It's also a good idea to use the addClass method of jQuery. – dkum Dec 07 '20 at 13:54
  • @Ivar Thx, I now just change the innerHTML of a div. And it works now :) – Tobias H. Dec 07 '20 at 14:24

0 Answers0