Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i use more than once $(document).ready() of jquery in a single html page?

i have one html page named "text.html"

<html>
    <body>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="js/Photos.js"></script>
        <script type="text/javascript" src="js/Animations.js"></script>
    </body>
</html>

Both Photos.js and Animations.js start with "$(document).ready()" like this

//Javascript File Photos.js
$(document).ready(function() {
    //My code here ....
});

//Javascript File Animations.js
$(document).ready(function() {
    //My code here ....
});

Does it matter if i use multiple $(document).ready(function() { in a single html page??

Thanks, in advance

like image 355
programmer Avatar asked Aug 18 '11 14:08

programmer


1 Answers

You can use as many as you would like, but its best to keep it to one for readability.

Also consider using short hand $(function() { ... });

like image 101
wesbos Avatar answered Sep 29 '22 12:09

wesbos