Can you confirm/explain this?
If jQuery is included after the js-file, any jQuery in the js-file won't be carried out, because the jQuery has not been included yet:
<script src="js_test.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
Then, if my javascript file looks like this:
alert('javascript is working');
(function(){
alert('ordinary javascript in self-invoked function');
})();
$(function() {
alert('this is jQuery');
});
... the two javascript alerts will be carried out (not the jQuery alert).
But if I put the jQuery on top, like this:
$(function() {
alert('this is jQuery');
});
alert('javascript is working');
(function(){
alert('ordinary javascript in self-invoked function');
})();
..then the remaining javascript is not carried out either.
So the rule seems to be that if jQuery included improperly, the javascript file will be read to the point where any jQuery appears, then it stops reading the script. Is this true?
I thought it would be able to read the script anyway and carry out the strictly javascript based code.