jquery ready() method


  Translation results:

ready

English [ˈredi] American [ˈrɛdi]

adj. Ready, ready-made; immediate, agile; willing; upcoming

vt.Be prepared for…

adv.Advance;completed

n.Cash

jquery ready() methodsyntax

Function: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. The ready() function specifies the code to be executed when the ready event occurs. The ready() function only works on the current document, so no selector is needed.

Syntax 1: $(document).ready(function)

##Syntax 2: $().ready(function

Syntax 3: $(function)

Parameters:

ParameterDescriptionfunction Required. Specifies the function to be run when the document is loaded.

jquery ready() methodexample

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.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>
Run instance »

Click the "Run instance" button to view the online instance

Popular Recommendations