-3

I am new to JS. I actually thought I could edit html pages from external js files. It works when i put my codes in functions. But outside that, i get this error.

Uncaught TypeError: Cannot set property 'innerHTML' of null

Guys, am i missing something?

Here is my JS code.

var One = document.getElementById("one");
var script = "Your message has been received. One of our reps will contact your shortly";
One.innerHTML = script;
Satpal
  • 126,885
  • 12
  • 146
  • 163

1 Answers1

-1

This error typically occurs if you are trying to call a function in an object, but you typed the name wrong. please check it and follow dis rule.

  • Thank you Manthan. I beleive i did exactly as you suggested and still same error. Howbeit. Let me ask you a default question. Is it possinle to manipulate the DOM from an external script WITHOUT using functions? How do you target specific pages eith javascript from an external file? – Kingsley Ajebon Oct 31 '17 at 14:03
  • Ok, i have been able to solve the problem. Script tags linking to external file must be at the bottom of the page to allow DOM load. – Kingsley Ajebon Oct 31 '17 at 14:55