I believe that is actually impossible, (the fact that $
would be undefined
), the document head loads synchronously meaning each line is fully loaded before the next line
There is a video here where this exact test is put to the test and it seems I was correct
Video: http://www.bennadel.com/blog/1915-How-Javascript-Loading-And-Blocking-Works-By-Default.htm
are you loading the files correctly such as
<!DOCTYPE html>
<html>
<head>
<title>...</title>
<script type="text/javascript" src="...."></script>
<script type="text/javascript" src="...."></script>
<script type="text/javascript" src="...."></script>
<script type="text/javascript" src="...."></script>
<script type="text/javascript">
jQuery.ready(function(){
//This is executed once all 4 above have been loaded
});
</script>
<script type="text/javascript" src="...."></script>
<script type="text/javascript" src="...."></script>
<!-- The above to scripts are loaded in order after the jquery function has run. -->
</head>
</html>
the ready
method of jQuery only gets fired once the hole document has been loaded, until the DOM see's the final ending tag, usually </html>
[citation needed]
having said that its impossible, it may be possible in IE8 or lower, the reason for this is because IE is possibly the worst browser ever made, but they have said that IE9 has totally had a overhaul and should content with the likes of Google, Apple, Mozilla etc
If your using multiple libraries or your overwriting the $
variable you can get it bac inside a locked scope like so:
(function($){
$.ready(function(){
//Do your jQuery here !
});
})(jQuery)