Подождите, пока DOM загрузит JavaScript

document.addEventListener('DOMContentLoaded', (event) => {
  //the event occurred
})
Breakable Bison