HI WELCOME TO SIRIS

jQuery Document Ready – $(document).ready()

The jQuery Document Ready makes sure the page DOM is ready for the code to execute. All the jQuery Codes are placed inside it.
1
2
3
$(document).ready(function() {
    alert('DOM is Ready');
});
We can also use the shorthand $() for $(document).ready().
1
2
3
4
// Shorthand for $( document ).ready()
$(function() {
    alert('DOM is Ready');
});

Example of a Button Click

In this example I will show how to place a button click event in jQuery. I will place this event inside the $(document).ready().
1
2
3
4
5
$(document).ready(function(){
    $("button").click(function(){
       alert('Button is Clicked');
    });
});
Note – In the above code If you do not place the button click event inside document ready function then you will find the code not executing at all.
Therefore always place all your codes inside jQuery Document Ready function.