[Solved] I can’t reach an element from HTML by using Javascript


You’re not passing the data from your index.html to game.html. So when you call this:

<a href="https://stackoverflow.com/questions/55249162/game.html" class="button" id="startCyber">START</a>

You’re loading a new page, which removes all of your existing variables – including ‘color1’.

I see 2 options here:

  1. Make this a single-page web app. So when you click your START button, it hides the index div and loads a game div
  2. Save your values from index.html somewhere (browser storage?) and then call that after you load your new game.html page.

solved I can’t reach an element from HTML by using Javascript