score:0

Accepted answer

You need to load js after the DOM is redered. You can either put the <script></script> in the bottom of your <body></body> or have it inside the following javascript method.

    document.addEventListener("DOMContentLoaded", function(event) { 
          //your code here
     });

Related Query