I always get confused by this when I'm working on large websites and am including a bunch of alien JS files and am trying to debug stuff.
If I have
<script type="text/javascript">
$(document).ready(function(){
console.log("foo");
});
$(document).ready(function(){
console.log("bar");
});
</script>
then does that guarantee console.log("bar")
is triggered immediately after console.log("foo")
??? Is it the same if I have
<script type="text/javascript" src="script1.js"></script>
<script type="text/javascript" src="script2.js"></script>
where script1.js
consists of
$(document).ready(function(){
console.log("foo");
});
and script2.js
consists of
$(document).ready(function(){
console.log("foo");
});
What happens when I add window.onload
and document.onload
into the mix, e.g.
<script type="text/javascript">
$(document).ready(function(){
console.log("foo");
});
window.onload = function() { console.log("John Skeet"); };
$(document).ready(function(){
console.log("bar");
});
window.onload = function() { console.log("Bjarne Stroustrup"); };
</script>
?????
Can someone here explain, or lead me to the documentation that explains, the rule for how these "fire after everything else" functions get stacked?