2

Sometimes I end up with a lot of code in the $("document").ready() function which usually sits inside the .html file.

 $("document").ready(function() {
    // The DOM is ready!
    // Let the DOM manipulation begin!
 });

What are the best practices for locating the $("document").ready(). Should it be in a different .js file and included in the HTML using:

<script src="MyDocReadyJS.js"></script>
Dmitri Tsoy
  • 561
  • 6
  • 21
dr_rk
  • 4,395
  • 13
  • 48
  • 74
  • _for locating the `$("document").ready()`_? – Tushar May 26 '16 at 15:22
  • Best practice is to not to use it, move the ` – Tushar May 26 '16 at 15:23
  • Usually the HTMLs are long and adding a `$('document').ready()` to this with lines of javascript make the overall code very cluttered. Looking for a cleaner way of doing this. – dr_rk May 26 '16 at 15:24
  • Related/Dupe of [`Why $(document).ready need after – Tushar May 26 '16 at 15:27

1 Answers1

1

The best practice is to put the code before you close </body> tag.
In this case you can get rid of "document ready" wrapper because the DOM will be already ready :)

Vitalii Petrychuk
  • 14,035
  • 8
  • 51
  • 55