@peanutbutterjlly
Posted
hey 👋,
When JavaScript code is placed at the top of an HTML webpage, it may not work as expected because the JavaScript code gets executed before the HTML content is fully loaded and parsed by the browser. This can lead to issues when the JavaScript code relies on accessing HTML elements or interacting with the DOM (Document Object Model).
To avoid this issue, it is recommended to place JavaScript code at the bottom of the HTML file, just before the closing </body> tag. This ensures that the HTML and CSS have been fully loaded before the JavaScript code is executed, which can prevent issues with the JavaScript code
Another solution is to use the defer attribute in the tag. This attribute tells the browser to defer the execution of the script until the HTML and CSS have been fully loaded.
StackOverflow: javascript at bottom of webpage
hope my info and that stack overflow question helped!
oh and by the way, your page/solution looks great!
Marked as helpful
@calebomondi
Posted
@peanutbutterjlly Now I know better, and thank you for the complement.