I only have access to body content and not the header or footer, Jquery is loaded in the footer of each page, so when my scripts load in the body, they have errors like "$ is not defined". When I try to load the scripts on dom ready I still get the error because it is still loading before the main jquery. Is there anything I can do to get the jquery in the body to load AFTER the footer script?
FURTHER EXPLANATION: I did search to see what other users had posted and didn't run across this particular situation. I tried a simple
$(document).ready(function () {
and it didn't work. I'm trying to get a form validation script to work and still keep getting
Uncaught TypeError: $(...).validate is not a function
Using the answer below did fix some of the issues but not this one. My code is:
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script type="text/javascript">
window.addEventListener('load', function () {
$.getScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js");
$.getScript("https://ajax.aspnetcdn.com/ajax/jquery.validate/1.17.0/jquery.validate.min.js");
$.getScript("https://ajax.aspnetcdn.com/ajax/jquery.validate/1.17.0/additional-methods.js");
});
</script>
<script type="text/javascript">
window.addEventListener('load', function () {
$('#commentForm').validate({ // initialize the plugin
rules: {
email: {
required: true,
email: true
},
mobile_phone: {
required: true,
phoneUS: true
}
},
submitHandler: function (form) { // for demo
//alert('valid form submitted'); // for demo
var $phone_temp = $('#mobile_phone').val();
$('#mobile_phone').val($phone_temp.replace(/\D+/g, ''));
form.submit();
}
});
});
</script>
<!-- in footer: using for local testing -->
<script src="https://.../jquery.js"></script>
<script src="https://.../bootstrap.js"></script>