Why doesn't my setInterval function run more than once?

Viewed 79

I don't know why my function is not properly called every 100 milliseconds. It is just called once, when the page is loaded/reloaded. I am out of ideas what to try.

var unit = document.getElementsByClassName('unit');
var date = new Date();

function setTime() {
  hour.textContent = date.getHours();
  unit[0].textContent = "h";
  minute.textContent = date.getMinutes();
  unit[1].textContent = "m";

  console.log('boom');
}

setInterval(setTime, 100);
<h1 id="time">
  <span id="hour"></span><!-- 
  --><span class="unit"></span> 
  <span id="minute"></span><!-- 
  --><span class="unit"></span>
</h1>

0 Answers
Related