Friday, October 28, 2016

$(document).ready()

For jQuery to load properly we want to make sure that the document which is the html or the DOM file loads fully first.  Incasing your jQuery in $(document).ready() tells jQuery to hold up and wait its turn.

Here's an example:

//wait till the document file has loaded then executes a function (with no parameters)
$(document).ready(function() {
//print out "Hello" to the console.
  console.log("Hello");
//close
})

You can also do the short hand.

//the (document).ready is optional. 
$(function() {
  console.log("Hello");
})

No comments:

Post a Comment