jQuery $(document).ready() shorthand – domready
Categories:
javascript
›
jQuery
jQuery .ready()
JavaScript provides the load event for executing code when a page is rendered. This event gets triggered when the download assets such as images has completed. However, most people want their script to run as soon as the DOM hierarchy has been fully constructed. jQuery provides the .ready() for just this purpose. This is the corresponding domready function in Mootools.
$(document).ready(function() {
// your code
alert('Page: ' + $('title').html() + ' dom loaded!');
});
$(function() {
// Handler for .ready() called.
alert('Page: ' + $('title').html() + ' dom loaded!');
});
jQuery.noConflict();
(function($) {
$(function() {
// by passing the $ you can code using the $ alias for jQuery
alert('Page: ' + $('title').html() + ' dom loaded!');
});
})(jQuery);
.ready() Handler
The handler passed to .ready() is guaranteed to be executed after the DOM is ready. This is usually the best place to attach all other event handlers and run other jQuery code. If .ready() is called after the DOM has been initialized, the new handler passed in will be executed immediately.

