Document ready is a handler that runs once the DOM is loaded in the browser. Since the browser loads item from the top down, use .ready() when you are referencing DOM elements in script where the script is loaded before the elements.
Embryologist
What happens if I ignore document.ready in my scripts?
That depends on your design. I suggest that you learn scope and closures in JavaScript.
All-Star
53041 Points
23616 Posts
Re: document.ready function
Jun 04, 2017 11:53 AM|mgebhard|LINK
Document ready is a handler that runs once the DOM is loaded in the browser. Since the browser loads item from the top down, use .ready() when you are referencing DOM elements in script where the script is loaded before the elements.
That depends on your design. I suggest that you learn scope and closures in JavaScript.
https://developer.mozilla.org/en-US/docs/Glossary/Scope
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures