This is probably the first thing to learn about jQuery. Everything inside the $(document).ready() function will execute as soon as the DOM is registered by the browser and before the page contents are loaded. So if you want an event to work, call it inside this handler. This means that everything you stick inside the brackets is ready to go at the earliest possible moment, which allows hiding and showing effects and other dynamic functionality when the user sees the page elements.
Read more: