Two events that the document has completed loading
Ready, indicates that the document structure has been loaded (not including pictures and other non-text media files) onload, which indicates that all elements of the page including a picture, such as a non text media file, are loaded.
1. DOM Ready
Document loading order: Domain name resolution--> loading html--> loading JavaScript and css--> loading pictures and other non-text media files.
Dom ready can operate on the DOM when it means that the DOM load is complete, between the loading of JavaScript and CSS and text-loaded media files such as pictures.
For example, you can set the properties or styles of a picture as long as the tag is loaded and you do not have to wait for the picture to load.
There is no direct method of Dom ready in native JavaScript.
jquery's Ready () method:
$ (function () {
...
});
Equivalent to
$ (document). Ready (function () {
...
});
Equivalent to
$ (). Ready (function () {
...
});
2. DOM Load
Document loading order: Domain name resolution--> loading html--> loading JavaScript and css--> loading pictures and other non-text media files.
Dom load, after loading a non-literal media file such as a picture, means that the DOM cannot be manipulated until the document is loaded, including non-text media files such as loading pictures.
For example, you need to wait for the picture to be loaded before you can set the properties or style of the picture.
Use the OnLoad event in native JavaScript.
Window load:
Window.onload = function () {
...
}
Picture load:
document.getElementsByTagName ("img") [0].onload = function () {
...
}