In jQuery you can wrap all your code in $(function() { ... }); and have it fire when the DOM is ready, but what if you want to put that in the middle of the page somewhere? Isn’t it possible that the DOM ready event will fire before it processes that chunk of code and it’ll get missed? Is there a way to guarantee it’ll get fired?
In jQuery you can wrap all your code in $(function() { … }); and
Share
You can place a
<script>..</script>block anywhere in your code:if you use
.ready()(or equivalent syntax) to execute code when the dom is loaded, it will be executed when the whole page is loaded, no matter where you placed theready()handler.if you simply put code within the
<script>tags, then it will be executed whenever the parser reaches that point of the code.