< /script>

Home >Web Front-end >JS Tutorial >How to use ready in jqurey

How to use ready in jqurey

一个新手
一个新手Original
2017-09-30 09:02:411704browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to use AJAX, specificNext article:How to use AJAX, specific