0
Help for clear this code
I can't understand what was the mistake function hi() { var ab=document.getElementById('start'); ab.innerHTML="hello"; } hi();
11 Respostas
+ 2
You have to load it after HTML, either by,script tags at the bottom of body. Or by using window.onload = () => {your code}.
+ 2
It loades in head tag, so it executes before there is any element. Then you have to use window.onload
+ 2
If placed in JS page it is automatically placed to head tag in HTML. So it executes when head is loaded. But in that time there is no body tag (with all child nodes) loaded. So it throws undefined as the variable value. Got it?
+ 1
I used script tag bottom of the body but error is show innerHTML null
+ 1
Are you sure you have element with id 'start'?
+ 1
Or better post whole code via code playground, then i will be able to help you more
+ 1
But if I write this code in js section what is the wrong?
+ 1
Sorry but plz explain more
+ 1
BTW thank you very much for helping