$(document).ready(function(){
//code here
});
The code above is used almost every time when we work with jQuery. Also other variations like $(function(){ //code here }) and some more. This code is used when we want to initialize our jQuery codes after the DOM is ready. document.ready is a jQuery event, it runs when the DOM is ready, e.g. all elements are there to be found/used, but not necessarily all content.
------------------------------
Question? do we need $(window).load() for?
Sometimes you want to manipulate pictures. For example you want to verticaly and horizontaly align a picture and you need to get the width and height of the picture in order to do that. With $(document).ready() you won’t be able to do that if the visitor doesn`t have the image already loaded, in which case you need to initialize the jquery alignment function when the image finishes loading. That`s where we use…
$(window).load(function(){
//initialize after images are loaded
});
window.onload fires later(or at the same time in the worst/failing cases) when images and such are loaded, so if you`re using image dimensions for example, you often want to use this instead.
- Nitin Pratap Singh
If you love this article please like, share or comment!
Net NeutralityThe principle that Internet service providers should enable access to all content and applications regardless of the source, and without favouring or blocking particular products or websites.
Bind the custom function with twitter eventLoading the widgets.js file asynchronously will require you to wait before binding events. You will need to wrap your event bindings in a callback function which will be invoked once everything has loaded.
Sensitivity of Digital DataIn the world of computer, tab and mobile; how to use these gadget is important concern. Some of instance experienced in our day to day life, these can’t be ignore...