I\'ve picked up an existing project from another developer and ive noticed in the code that they are executing js code within three different event handlers...
f
pageLoad
and the jQuery ready
handler are both methods of accomplishing similar things.
The second two examples are identical.
http://encosia.com/document-ready-and-pageload-are-not-the-same/
$(document).ready(function() {
`enter code here`
//execute code
});
$(function() {
`enter code here`
});
Both functions perform task in the same way, executes code inside them once the document is ready.
function pageLoad() {
`enter code here`
}
This executes after every post back, generally used with update panels controls as the above two functions does not execute every time or every post back.
$(document).ready()
will not fire for the partial postbacks (happened from AJAX). In that case, you should use MS AJAX
pageLoad function when you need to execute something when the page loads either from the full postback or partial.
The article given in the Encosia site is a good read.
$(document).ready()
Ideal for one time initialization.
Optimization black magic; may run slightly earlier than pageLoad().
Does not re-attach functionality to elements affected by partial postbacks.
pageLoad()
Unsuitable for one time initialization if used with UpdatePanels.
Slightly less optimized in some browsers, but consistent.
Perfect for re-attaching functionality to elements within UpdatePanels.
In this site you will find the difference :)
Document.ready Vs pageLoad
The last one is just a shorthand notation of the one above it. http://www.jquery4u.com/dom-modification/types-document-ready/