+ 7
You are running your code before DOM is created. Try running your code in a window.onload function, like below: window.onload = function(){ var Start="Gyu"; var Star=Start.substring(0,1); var Fir=document.getElementById("A"); Fir.innerHTML=Star; }
26th Oct 2017, 5:14 AM
Ankit Agrawal
Ankit Agrawal - avatar
+ 5
It means document.getElementById("A") is being called before the div is even created. window.onload function will wait till all the DOM elements i.e. html elements are constructed and then it will executed the code block.
26th Oct 2017, 7:21 AM
Ankit Agrawal
Ankit Agrawal - avatar
+ 2
SoloLearn detail: The [JS] tab is inserted into <head> and starts running before <body> is parsed. Some people put <script> at the end of <body> -- I did this to be more clear -- but the event-driven approach (onload) is the better one.
27th Oct 2017, 5:41 PM
Kirk Schafer
Kirk Schafer - avatar