Difference between window.onload and document.ready
The difference between
window.onload
and document.ready
is as follows.
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.
Example:
<script>
function myFunction()
{
alert("Javascript Page load");
}
$(document).ready(function() {
alert("Jquery Page load");
});
</script>
In the example above"Jquery Page load" alert will load first and then "Javascript page load" alert loads.
Comments
Post a Comment