Why does [removed] event occur before $(document).ready?

前端 未结 3 1123
一整个雨季
一整个雨季 2021-02-20 01:10

As stated in this thread: window.onload vs $(document).ready(). The window.onload should occur later than the $(document).ready() but in this simple co

3条回答
  •  旧时难觅i
    2021-02-20 01:39

    The problem is not with the order of the events. It with the jQuery wrapper around the native DOM events. If you try the native DOMContentLoaded you will find that it always runs before window.onload. But the jQuery event $(document).ready will come some milliseconds after DOMContentLoaded, which in some cases might be after window.onload too, especially if the page doesn't have much to load like the code below. This is delay is due to jQuery implementation.

    If you uncomment the iframe in the code though, it takes some time to load which causes the window.onload to be delayed, so $(document).ready will come first.

    
    
    
    
        
    
    
    
        

    A Simple Site

提交回复
热议问题