Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between pageLoad , onload & $(document).ready()

i need to know in more detail of what is the differences between pageLoad , onload & $(document).ready()

I found answer but that is not ver clear to me. the answer is like

The ready event occurs after the HTML document has been loaded, while the onload event occurs later, when all content (e.g. images) also has been loaded.

The onload event is a standard event in the DOM, while the ready event is specific to jQuery. The purpose of the ready event is that it should occur as early as possible after the document has loaded, so that code that adds funcionality to the elements in the page doesn't have to wait for all content to load.

the person trying to say ready event occurs after the HTML document has been loaded and onload event occur after all page element like image etc being loaded.

So what is HTML document load? I know HTML document load means all page element load complete.

What does mean like dom is ready or loaded? What is the difference between HTML document load & dom load? Please make me understand with example. Thanks

like image 235
Keith Costa Avatar asked Nov 01 '11 19:11

Keith Costa


People also ask

What is difference between onload and ready?

onload() fires when all the content (everything) on the targeted eleement is fully loaded like CSS, images etc. $. ready indicates that code in it need to be executed once the targeted elements content loaded and ready to be manipulated by script. It won't wait for the images to load for executing the jQuery script.

What is the difference between window onload and document onload in JavaScript?

The general idea is that window. onload fires when the document's window is ready for presentation and document. onload fires when the DOM tree (built from the markup code within the document) is completed.

What is onload used for?

onload is most often used within the <body> element to execute a script once a web page has completely loaded all content (including images, script files, CSS files, etc.). However, it can be used on other elements as well (see "Supported HTML tags" below).

What is pageLoad function in JavaScript?

pageLoad() is a function that pages with an ASP.NET ScriptManager (i.e. MicrosoftAjax. js) will automatically execute after ASP.NET AJAX's client-side library initializes and then again after every UpdatePanel refresh.


1 Answers

I don't know what you mean by pageLoad, but here's some info on onload and $(document).ready().

window.onload fires when everything in the page has finished loading. That means that not only the entire DOM is loaded, but any linked resources such as images are fully loaded. Because this waits for images to finish loading, it can sometimes take a long time to fire window.onload. Unless you really need to wait until images are finished loading, you do not generally want to wait this long to start running your javascript that modifies the page or hooks up event handlers, etc...

$(document).ready() is a jQuery-specific event that fires as soon as the DOM is ready for manipulation, but potentially long before images have finished loading. This occurs after all objects present in the page HTML have been parsed and initialized by the browser and after all scripts in the page have been loaded. At the moment of this event, it is safe to modify the DOM in all browsers. This even may occur a little earlier or later in some browsers as the mechanism for detecting when the DOM is safely loaded varies between older and newer browsers.

The jQuery 1.6.x implementation for $(document).ready() uses a number of different detection mechanisms for when the DOM is ready. The preferred method is when the DOMContentLoaded event triggers on the document object. But, this event is only supported by some browsers so it has fallback mechanisms for other browsers.

Both of these events will fire only once per page.

like image 180
jfriend00 Avatar answered Oct 24 '22 02:10

jfriend00