Saturday, March 28, 2015

til: jquery $(document).ready shorthand

Oh, huh. Since I've know jQuery, I've used the formulation:

$(document).ready(function(){
  //do something
});

but in going over some jQuery UI example, I found out

$(function(){
  //do something
});

is a more concise replacement, that also waits for the DOM to be loaded.

Here's a pretty decent summary page including some other options.

No comments:

Post a Comment