<div class="actions">
<h3>Actions</h3>
<ul>
<li><a href="/configurations">Configurations</a></li>
</ul>
</div>
<script type="text/javascript" src="/jquery.min.js"></script>
<script type="text/javascript">
$('ul a').click(function(){
alert("");
});
</script>
In the above code is document.ready necessary. What i mean is, is there any case when js will be executed before html
.readyis a shortcut toDOMContentLoaded(oronreadystatechangeor an assortment of workarounds for other browsers). That event fires when the DOM has been built – in other words, when the whole HTML has been downloaded.So, as long as your script tags are the last thing before
</body>(they are not inside anydivs or other elements) the end result is the same, you don’t need$(document).ready. That is even recommended, since putting your scripts in the<head>will slow down the loading of content.Though I’d recommend you to adopt this pattern, to avoid problems with the
$global:These other questions are interesting reads: