Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery ready() method

jQuery ready() method

jQuery event methods jQuery event methods

Example

Use ready() to make a function available after the document has loaded:

$

(

document

)

.

ready

(

function

(

)

{

$

(

"

button

"

)

.

click

(

function

(

)

{

$

(

"

p

"

)

.

slideToggle

(

)

;

}

)

;

}

)

;

Try it »


Definition and Usage

The ready event occurs when the DOM (document object model) has finished loading and the page is fully loaded (including images).

Since this event occurs after the document is ready, it is a good practice to place all other jQuery events and functions inside this event. As shown in the example above.

The ready() method specifies the code to execute when the ready event occurs.

**Tip:** The ready() method should not be used together with .


Syntax

The following two syntaxes are allowed:

$(document).ready(

function

)

The ready() method can only be used on the current document, so no selector is needed:

$(

function

)

Parameters Description
function Required. Specifies the function to run after the document has loaded.

jQuery event methods jQuery event methods