0

Does getElementBy works in external js file ?

I have tried to fix it but every time i try to write document.getElementBy in external file it doesn’t respond but works properly with inline script tag. Is it so or i am wrong?

20th Feb 2019, 11:35 AM
Farid
2 Antworten
+ 1
You said document.getElementById() right?. The reason that the external js file is not working because it starts to execute instructions before fully loading the web page - as it is declared in the head before any element. The best way to wait until all elements load is to use the window.onload function. So it will wait until all the elements get loaded and then execute instructions without any error. Syntax: window.onload = function() { //your code here }
20th Feb 2019, 11:45 AM
Seniru
Seniru - avatar
20th Feb 2019, 1:44 PM
Gordon
Gordon - avatar