Here is a pretty safe way to run code on ready
jQuery(function($, undefined){
// code to run onready
});
Although I personally prefer doing it like this:
(function($){ // create scope and pass specific aliased variables
$(function($, undefined){ // attach callback to run onready
// code to run onready
});
})(jQuery);
This way you can make your own bundles of functionality without fear of breaking other peoples code or having your code broken by loose variable definitions. You can also call the variables that you pass along with whatever names that you want and have code that runs no on ready, for example.
(function($){ // create scope and pass specific aliased variables
$(document).on('click', 'a[href]', function(){
// code to run when a link is clicked
});
$(window).on('load',function(){
// code to run onload
});
$(function($, undefined){ // attach callback to run onready
// code to run onready
});
})(jQuery);
Note that these are the same
$(document).bind('ready', function(){});
$(document).on('ready', function(){});
$(document).ready(function(){});
$(function(){});
And that document does not have a load event
$(document).on('load', function(){}); // will not work