JSFiddle - React, Tailwind, and code Playground

by fxi

HTML

<span id="count">0</span>
<button id="stop">stop</button>
<img src="https://app.requestly.io/delay/3000/https://picsum.photos/200/300">

JavaScript

let i = 0;
const elStop = document.getElementById('stop');
const elCount = document.getElementById('count');

elStop.addEventListener('click', cancel)

update();

function update() {
  elCount.innerText = i++;
  setTimeout(update, 1e3);
}




async function cancel() {
  console.log('stop');
  window.stop();
}