+ 1
Why this is code not working in here
2 Answers
+ 2
Because the javascript is loaded before the html document, and you are using methods in your code to select html elements that have not yet been loaded.
You need to use the onload event to wait until the html document is fully loaded:
onload =()=>{ Your code }
+ 2
Dhananjay Chaudhary, You can use event listeners to solve this problem:
window.addEventListener('DOMContentLoaded', (event) => {
//Put your JS code here
});
Read more here:
https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event