-1

I made some tabs on my page but buttons don't work unless they are on the home tab. Also all js code i put below an event listener that is connected to a button in a different tab than default one does not work.

https://github.com/Vritta531/Vritta

I really don't know if this issue is related to the way I coded tabs or something else. I'm still a beginner. I would appreciate any help.

Vritta
  • 3
  • 1

1 Answers1

0

Simply move your <script> tag to the bottom right before the <body> end.

If you run your code and check the browser console it's saying:

"game.js:116 Uncaught TypeError: Cannot read property 'addEventListener' of null at game.js:116"

Cause: Because you put the <script> tag before button with id="uppickaxe". Since your script tag occurs before the element exists so it returned as undefined/null.

...
<!-- INITIALLY HERE
<script src="game.js"></script>
 -->
  
<div id="Shop" class="tabcontent">
    <h3>Shop</h3>
    <button id="uppickaxe">Pickaxe || 1000 Wood</button>
</div>

<div id="Settings" class="tabcontent">
    <h3>Settings</h3>
    <h3>Work in progress...</h3>
</div>

<!-- MOVE JS HERE -->
<script src="game.js"></script>

</body>
</html>

Developer
  • 54
  • 6