How to check if DOM is ready without a framework?

前端 未结 6 1246
有刺的猬
有刺的猬 2020-11-27 12:39

The question is so like a zillion others here and on the web - How to check if DOM has loaded in Javascript? But here\'s the catch:

  • Without using a framework l
6条回答
  •  [愿得一人]
    2020-11-27 13:20

    The DOMContentLoaded event is fired when the initial HTML document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading.Good thing is chrome, firefox, IE9, opera and safari supports it equally

    document.addEventListener("DOMContentLoaded", function(event) 
    {
        console.log("DOM fully loaded and parsed");
    }
    

    NOTE : Internet Explorer 8 supports the readystatechange event, which can be used to detect when the DOM is ready.

提交回复
热议问题