Run Jquery after page has loaded
Following is the code that needs to be put to the header of the page (in head tags) and that we use to run jquery only after the page has loaded:
$(window).bind(“load”, function() { // code here });
Following is the code we use in Jquery to run when the DOM is ready:
$(function() { // code here }

whats the different between the page has loaded and DOM is ready?
page loaded means all of the page (eg. pictures loaded), dom is ready means the "sceleton".
To be completely correct second statement should be:
$(function() {
// code here
});
document ready means the DOM is loaded to it's completion, but doesn't necessary mean images are loaded.
document.ready is typically the preferred mechanism.
Sure but if you nest this inside of document.ready, you get a command that waits until the page is ready. This is important when dynamically sizing DIV areas (div height is equal to view portal minus header+footer or some such thing - if that calculates early you get no scroll bars)
Post Comment