ready() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:ready

Description

The ready event occurs when the DOM has been loaded.

Syntax

The ready() method can only be used on the current document:

Parameter Require Description
function Required. function to run after the document is loaded

The following code shows how to Use ready() to make a function available after the document is loaded:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").slideToggle();
    });//from w w w .j  a v  a2 s  . c  o m
});
</script>
</head>
<body>

<p>This is a paragraph.</p>

<button>Toggle between slide up and slide down for a p element</button>

</body>
</html>

Related Tutorials