Home > Web Front-end > JS Tutorial > body text

How to use ready in jqurey

一个新手
Release: 2017-09-30 09:02:41
Original
1625 people have browsed it

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>
Copy after login

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、$();
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!