/script>
Home > Article > Web Front-end > How to use ready in jqurey
ready activates the function after the document is loaded
Example:
<html> <head> <script type="text/javascript" src="/jquery/jquery.js">< /script> <script type="text/javascript"> $(document).ready(function(){ $(".btn1").click(function(){ $("p").slideToggle(); }); }); </script> </head> <body> <p>This is a paragraph.</p> <button class="btn1">Toggle</button> </body> </html>
Definition and usage:
The ready event occurs when the DOM (Document Object Model) has been loaded and the page (including images) has been fully rendered.
Since this event occurs after the document is ready, it is a good practice to place all other jQuery events and functions in this event. Just like in the example above.
ready() function specifies the code to be executed when the ready event occurs.
ready() function only works on the current document, so no selector is required.
The following three syntaxes are allowed:
1、$(document).ready(); 2、$().ready(); 3、$();
The above is the detailed content of How to use ready in jqurey. For more information, please follow other related articles on the PHP Chinese website!