Does it matter if i use multiple $(document).ready(function() { in a single html page??
No it doesn't matter and in some (read: many) cases is the correct way to do. However, like always, I like to give some (useful) pointers:
As you mentioned in a comment, technically adding the file-call before </body>
does mean, that you basically don't need to use $(document).ready()
. I personally try to avoid as much as I can, since jQuery isn't that strict as JS alone (meaning: most of scripts work without $(document).ready()
).
[EDIT: This part of my answer is not accurate, please see comments below] Also, it is not wise to add the jquery inside in the footer, or even in the <body>
. It is technically not incorrect, but if you are dealing with a cms-like software or some template feature, then you want all the pages to have jQuery included. OR you can just call it my oldschool knowledge.
Since you want to call the Photos.js and Animations.js in the footer, I assume, they are not proper plugins. If you want to make your code tighter, then compose them into correct plugin. Then you can add the plugins in the header and have single footer file, in what you assign the plugins to elements (read: activate them.) Here is a quick tutorial on how to create your own plugins.
Also, if you have multiple JS files, that must get included to the page. Then you could make your code neater by using $.getScript()
. You must add jQuery first like always, but calling the other files can be done in one <script>
tag. Looks neater and it seems to be a little faster as well (at least in your own head.) I give you a little example:
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<!-- Content camps here -->
<script type="text/javascript">
$.getScript('js/Photos.js');
$.getScript('js/Animations.js');
</script>
</body>
</html>