jQuery Document Ready

The jQuery document ready event is used to prevent any jQuery code from running, while your page is loading.

If you use jQuery without it, so it may be possible that your script will not work.

Best Example can suppose your code is written in the head section and executes to change something in the footer section, but footer section is not fully loaded, in this case, your code will not work.

Syntax:
$(document).ready(function(){

   // write your code here...

});

or you can also use an even shorter method.

$(function(){

   // write your code here...

});

An example of document ready method

Example:
$(document).ready(function(){
    $("div").click(function(){
        $(this).addClass("selected");
    });
});

On the above example, clicking on the div tag will add a newly selected class on self.