Search code examples
javascripthtmlinnerhtml

JS Not Changing innerHTML


I want it so that it will always say You Have (amm)

Here Is My HTML

<div class="box" id="burger">
    <img src="./images/burger.png" alt="Burger" width="80%" height="auto"><br>
    <a class="title">Burger</a><br>
    <a class="price">Price : 3$</a><br>
    <a class="amount">You Have ___</a><br>        <!-- THIS LINE --> 
    <a class="buy" onclick="buy('burger', 3);">Buy  </a><a class="sell">  Sell</a>
</div>

And Here Is My JS

setInterval(function(){
  document.getElementById("burger").getElementsByClassName('amount').innerHTML = "You Have " + burgers;
}, 1);

Solution

  • getElementsByClassName returns an array of all elements with that class name. if you want to change the first element with that class name, try

    getElementsByClassName('amount')[0].innerHTML