Tutorial Loading jQuery

by in , 0

Load with Google API

<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
    google.load("jquery", "1.2.6");
</script>
<script type="text/javascript" src="js/example.js"></script>

Direct Link to Google

<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2'></script>

Check if loaded, only load if unloaded

var jQueryScriptOutputted = false;
function initJQuery() {

   //if the jQuery object isn't available
   if (typeof(jQuery) == 'undefined') {


       if (! jQueryScriptOutputted) {
           //only output the script once..
           jQueryScriptOutputted = true;

           //output the script (load it from google api)
           document.write("<scr" + "ipt type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></scr" + "ipt>");
       }
       setTimeout("initJQuery()", 50);
   } else {

       $(function() {
           //do anything that needs to be done on document.ready
       });
   }

}

Reference URL

Leave a Reply