Menu Close

How to use $( document ).ready() method in jquery?


The $(document).ready() is used to make a function of our codes to execute after the document is loaded. We have to write our codes inside the $(document).ready() method. It will run once the page DOM is ready to execute JavaScript code.

We can use two syntax in this method.



The ready() method is used only for current documents. So the selector is not required. We can also replace the above syntax as follows. These two syntax are the same and we can use either one of these.


Follow the below example to learn about how to use $(document).ready() method in jquery.


<!DOCTYPE html>
<html lang="en">
    <title>$( document ).ready() method in jquery</title>
    <meta charset="utf-8">
    <script src=""></script>
    <meta name="viewport" content="width=device-width, initial-scale=1">
                alert("Hello, world!");
    <div class="ready-method">
        <button>Click me!</button>
Posted in HTML, jQuery, Web Technologies

You can also read...