Skip to content Skip to sidebar Skip to footer

What Does This Jquery Instruction Do $(function(){...})

I have been studying JQuery lately and, even though I know some stuff, there's this line in a book that I simply can't figure out: $( function() { current_entry = -1;

Solution 1:

It is short form of document.ready event. It is executed when DOM is ready.

All three of the following syntaxes are equivalent:

  • $( document ).ready( handler )
  • $().ready( handler ) (this is not recommended)
  • $( handler )

The handler passed to .ready() is guaranteed to be executed after the DOM is ready, so this is usually the best place to attach all other event handlers and run other jQuery code. When using scripts that rely on the value of CSS style properties, it's important to reference external stylesheets or embed style elements before referencing the scripts, jQuery api.

Post a Comment for "What Does This Jquery Instruction Do $(function(){...})"