Home >>jQuery Tutorial >jQuery ready() Method

jQuery ready() Method

jQuery ready() Method

jQuery ready() method in jQuery is used to specifies what happens when a ready event occurs when the DOM (document object model) has been loaded.

Syntax:

Two syntaxes can be used:

$(document).ready(function)

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

$(function)

Parameter Values

Parameter Description
function It is a required parameter and used to specifies the function to run after the document is loaded
Here is an Example of jQuery ready() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
$(".txt").slideToggle();
});
});
</script>
</head>
<body>
<p class="txt">This is Phptpoint</p>
<button class="btn1">click me to toggle p element</button>
</body>
</html>

Output:

This is Phptpoint


No Sidebar ads