-2

I've seen all three lines of below:

$().ready();
$(document).ready();
$(document.body).ready();

They all work, but which one is really the correct (or better) one to use? Taking in account the usage of the ready() event.

  • 1
    Which ones did you find in the docs for [`.ready()`](http://api.jquery.com/ready/)? Use documented code. –  Jul 31 '13 at 02:41
  • Duplicated question, they are all equivalent. – john 4d5 Jul 31 '13 at 02:44
  • I always use the $(document).ready(); variation. Just a personal preference though :-) – TGH Jul 31 '13 at 02:44
  • You could just also place your script tags at the bottom of your body tag. (In case you were planning on wrapping all your JS in .ready().) – Jackson Jul 31 '13 at 02:53

1 Answers1

2

None of these, I use $(function() {}) as it clutters the least, is shortest and very idiomatic.