jQuery - What are differences between $(document).ready and $(window).load?

前端 未结 8 2292
旧巷少年郎
旧巷少年郎 2020-11-22 02:45

What are differences between

$(document).ready(function(){
 //my code here
});

and

$(window).load(function(){
  //my code h         


        
8条回答
  •  离开以前
    2020-11-22 03:34

    This three function are the same.

    $(document).ready(function(){
    
    }) 
    

    and

    $(function(){
    
    }); 
    

    and

    jQuery(document).ready(function(){
    
    });
    

    here $ is used for define jQuery like $ = jQuery.

    Now difference is that

    $(document).ready is jQuery event that is fired when DOM is loaded, so it’s fired when the document structure is ready.

    $(window).load event is fired after whole content is loaded like page contain images,css etc.

提交回复
热议问题