When I have started learning I was bit confused about what is the difference between $(document).ready(function(){}) and $(window).load(function(){}) is all about and when does these scenarios will help while coding. I gone through so many articles in this regard from this web world and done some research on the same.
This article might help people who are at beginner level and what to know more about $(document).ready(function(){}) and $(window).load(function(){}) in jQuery.
$(document).ready(function(){}):
If you want to execute a function when the DOM [example: an 'element'] is fully loaded, then you can specify that function in $(document).ready(function(){});
If you want to know more about this, you can visit one good site named “learningjquery“. Karl Swedberg has explained clearly about the same with an example of how to start coding in jQuery.
1 2 3 4 5 |
<script language="javascript"> $(document).ready(function() { // execute when the DOM [example: an 'element'] is fully loaded }); script> |
$(window).load(function(){}):
This executes when the complete page is fully loaded that is when all items are fully loaded on the page which includes all images, iframes, objects etc., This helps when you want to play with images which has been loaded on the page, for example: if you want to know the width and height of the particular image or if you want to adjust the alignment of the image inside a ‘div’ element lets say vertical middle in a div.
1 2 3 4 5 |
<script language="javascript"> $(window).load(function() { // executes when complete page is fully loaded, including all images, iframes etc., }); script> |
If you have more examples of this sort, please do share the same in comments section below. It would help people like me to understand and to learn quickly
Related Entries...
-
This article will help beginners, that is who are new to jQuery and want to learn some tricks about j ...
-
Well today! I installed Shareaholic - SexyBookmarks widget in one of my wordpress blog. I've been wor ...
-
There might be some scenarios where we need to check whether a particular DIV is visible or not and i ...
-
Introduction: Below is the simple Bookmark script, which has been implemented using jQuery, this mig ...
-
Below snippet code helps you in getting mouse coordinates inside a div container, when user moves mou ...
-
Below is the code which is written in JavaScript, we can use this script for bookmarking the particul ...
-
'How to select elements which are having multiple classes using jQuery', this question has raised whe ...
-
To start with, Well I think bunch of developers might have come across this situations where in which ...
-
Here is a simple snippet on adding a "div" to the body tag dynamically using JavaScript, after going ...
-
Last week, I had a problem with flash object which is rendering dynamically on to my web pages. Actua ...
2 Responses
[...] Różnice pomiędzy $(document).ready(function() {}); a $(window).load(function() {});. Warto czasem wiedzieć co dzieje się pod [...]
Your site’s Share bar is obstructing half of the content. Please consider fixing it