Home >>jQuery Tutorial >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 | Description |
---|---|
function | It is a required parameter and used to specifies the function to run after the document is loaded |
<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>
This is Phptpoint