1// A $( document ).ready() block.
2$( document ).ready(function() {
3 console.log( "ready!" );
4});
1The .ready() method is typically used with an anonymous function:
2$( document ).ready(function() {
3 // Handler for .ready() called.
4});
5
6Which is equivalent to the recommended way of calling:
7$(function() {
8 // Handler for .ready() called.
9});
1// jQuery using anonymous function -------------
2$(document).ready(function() {
3 // ...
4});
5
6// jQuery using named function -----------------
7$(document).ready(sample);
8
9function sample() {
10 // ...
11}
12
13// jQuery Shorthand ----------------------------
14$(() => {
15 // ...
16});
17
18// ES6 -----------------------------------------
19// Use any of the following:
20// onDOMContentLoaded - DOM ready
21// onload - Page fully loaded
22// onloadeddata - Data loaded
23
24onDOMContentLoaded = (() => {
25 // ...
26})();
27