I’ve seen various examples use this and I’m curious to know, is it dangerous not to wrap jQuery code in the following?
$(document).ready(function () {});
I know what it does and I know why you do it but I’m curious if it is more unsafe or just bad practice/style to not have it? Thanks!
You use it if your code needs to access the DOM.
If you’re just setting up classes and modules, but not actually running them, then you don’t need to wrap them in the ready handler.
However, if you’re doing something that requires elements to be loaded (like, adding event handlers) then you need to do it in the ready() event.
EDIT:
Here is an example: http://jsfiddle.net/ctrlfrk/43n8U/
Try commenting out the addHandler functions and see what happens.
(Note that I’ve set jsfiddle to run this code in the head tag, by default it usually places the code in the onload event, which negates the need for the ready handler)