0

An error occurs in JS with the code below:

document.getElementById("p1").innerHTML = "New text!";

I tested different ways like this line and think there is a problem with innerHtml. I even copied some code but again an error:

Uncaught TypeError: Cannot set properties of null (setting 'innerHTML') what should I do?

some-user
  • 3,888
  • 5
  • 19
  • 43
  • Please share full code with html – Satish Thakur Oct 04 '22 at 05:02
  • please share your Html too; the problem is definitely from your html file – Parham Abolghasemi Oct 04 '22 at 05:26
  • Do you place your code before `#p1` in DOM and do not wrap in any DOM-ready event? If so - you execute code before browser has placed your element inside DOM – Justinas Oct 04 '22 at 07:24
  • You could also try to use `defer` to wait for the DOM to be fully loaded and then execute your JS code. It seems like your code tries to access an element that is not available in the DOM simply because either the element is not loaded in the DOM or placing issues with your script. `` – node_modules Oct 04 '22 at 07:27

0 Answers0