Question: Does anyone know how to check if jquery has been loaded (with javascript) then load it if it hasnt been loaded.

something like

```
if(!jQuery) {
    //load jquery file
}

```

Answer: 
Method 1:

```
if (window.jQuery) {  
    // jQuery is loaded  
} else {
    // jQuery is not loaded
}

```

Method 2:

```
if (typeof jQuery == 'undefined') {  
    // jQuery is not loaded
} else {
    // jQuery is loaded
}

```

If jquery.js file is not loaded, we can force load it like so:

```
if (!window.jQuery) {
  var jq = document.createElement('script'); jq.type = 'text/javascript';
  // Path to jquery.js file, eg. Google hosted version
  jq.src = '/path-to-your/jquery.min.js';
  document.getElementsByTagName('head')[0].appendChild(jq);
}

```
Even though you may have a head appending it may not work in all browsers. This was the only method I found to work consistently.

```
<script type="text/javascript">
if (typeof jQuery == 'undefined') {
  document.write('<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"><\/script>');        
  } 
</script>

```