Chúng ta có thể sử dụng sự kiện DOMContentLoaded được hơn 98% trình duyệt hỗ trợ (không hỗ trợ IE8):
document.addEventListener("DOMContentLoaded", function(event) { //do work });