I have a project where all the JS files are referenced in the footer, as is recommended for speed of page loading, including the link to the Jquery file. This code produces an "Uncaught ReferenceError", I assume because Jquery has not been defined before my script is called:
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
</head>
<body>
<p>
<a href="#" data-toggle="popover" title="first popover" id="example">hover over me</a>
</p>
<script type="text/javascript">
$(function(){
$('#example').popover({ trigger:'hover' });
})
</script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
</body>
</html>
If I move the Jquery link to the header, then the code runs fine, but this will slow the page loading time.
Is there a better way to declare my function so that it does not throw this UncaughtReference error, or is keeping the Jquery link in the head the best solution?