$(window).load() Vs $(document).ready() in jQuery

Difference between $(window).load() and $(document).ready() in jQuery


What is a DOM?


DOM: The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents.

$(window).load() -


The code which gets included inside $( window ).on( "load", function() { ... }) runs only once the entire page is ready (not only DOM).

$(window).load(function(){
   // executes when complete page is fully loaded, including all frames, objects and images
   alert("(window).load was called - window is loaded!");
});

$(document).ready() - 


The ready() method is used to make a function available after the document is loaded. Whatever code you write inside the $( document ).ready() method will run once the page DOM is ready to execute JavaScript code.

$(document).ready(function(){
   // executes when HTML-Document is loaded and DOM is ready
   alert("(document).ready was called - document is ready!");
});

Comments

Popular posts from this blog

How to Customize exported excel's cell background color in Datatables

Populate dropdown using jquery ajax in SharePoint

Clear DataTable on button click