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?
2 Réponses
+ 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
}
+ 1
You need lazy loading
https://code.sololearn.com/Wp6D6TIwpQ40/?ref=app