DEV Community

Farhana Binte Hasan
Farhana Binte Hasan

Posted on • Edited on

add a spinner in API js

Html code from bootstrap

<!-- added spinners -->
    <div id="spinners" class="spinner-grow text-secondary" style="margin:10rem 40rem;" role="status">
      <span class="visually-hidden">Loading...</span>
    </div>
Enter fullscreen mode Exit fullscreen mode

javascript code

const spinner = document.getElementById("spinners");
const loadData = () =>{
  spinner.removeAttribute('hidden');
    fetch('https://www.thesportsdb.com/api/v1/json/2/all_sports.php')
    .then((res) => res.json())
    .then((data) =>{
      spinner.setAttribute('hidden', '');
      displayData(data.sports)
    });
}
loadData()
Enter fullscreen mode Exit fullscreen mode

Top comments (0)