+ 2
External Js file not working for selecting elements!
I have 2 files, one html and another javascript file. I m trying to use getElement method in js file to select element present in html file. But it is not working. In HTML: <script src = 'script.js'> </script> <p>hi</p> <p>hello</p> <p>hi</p> ---------------------------- In script.js: var arr = document.getElementsByTagName("p") for (var x = 0; x < arr.length; x++) { arr[x].innerHTML = "Hi there"; } -------------------- It doesn't work!
3 Réponses
+ 5
Always set your dom access JavaScript script tag at the last element of the html document.
+ 5
Is it not working at all or is it giving error?
Link your code please.
+ 2
🤔 should work, can you post your project here?