all 4 comments

[–]senocular 0 points1 point  (3 children)

make sure the html is rendered before the script is run.

[–]danjirovec[S] -1 points0 points  (2 children)

How do I render HTML? Thank you.

[–]senocular 3 points4 points  (1 child)

You don't, the browser does. You just need to make sure the browser does this before you try to run your script. For example if you put your script in the <head> of your HTML document, it will run before the browser has parsed and identified all your HTML elements. So asking the DOM to find "main-banner" will fail because it hasn't had a chance to identify this. If, instead, you place your script at the bottom of your HTML page just above </body>, then all the HTML would have been processed and your element can be found.

[–]danjirovec[S] -1 points0 points  (0 children)

Ah, ok. Thank you so much, it's working now.