jQuery must wait for a page to be loaded before it can manipulate the page’s DOM
jQuery provides a “document ready” function that will run once the DOM is fully loaded
There are two ways to express the “document ready” function for jQuery
$(document).ready(function(){
// place your code here
// jquery code must be placed inside of a document ready block
})
$(function(){
// this is the same as the $(document).ready(function(){}) function
// just much less code
// place your code here
});
There are no advantages to choosing one syntax over the other. However, option #2 is less typing :)