views:

298

answers:

1

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
}
+7  A: 

Maybe something like this:

<script>
if(!jQuery)
{
   var script = document.createElement('script');
   script.type = "text/javascript";
   script.src = "path/to/jQuery";
   document.getElementsByTagName('head')[0].appendChild(script);
}
</script>
Daniel LeCheminant
Note that this assumes that the document has a `head` that it can append a script element to
Daniel LeCheminant
+1 had that exact implementation in my textbox when i noticed there was a new reply =)
David Hedlund
oh whoa, this is great. thanks!
seventeen