I don't think dependency matters as much as loading order of the whole file. $(document).ready
ensures that jQuery waits to execute the main function until
the page Document Object Model (DOM) is ready for JavaScript code to
execute.
Code outside this ready block might (be tried to) run before the page is actually ready. For instance, let's say this is code that's in the head
of your page:
<script>
jQuery(document).ready(function() {
jQuery('body').on('mouseup', '.some-div', function(e){
});
});
jQuery('.some-div').mouseup();
</script>
The ready block will wait, as described above, but the mouseup
trigger will try to fire, but it can't. The DOM isn't ready yet, which means .some-div
can't be found yet - and thus, the trigger can't be activated.
To improve the chances that DOM is ready, you can try to load your jQuery before the closing </body>
tag. The ready block can stay in the head
, but the trigger should then move to the end of the document to improve the likelihood that the DOM is ready (which it normally should at that stage). For an interesting read on where to place script
tags, also see this highly popular post.