Saturday, May 11, 2013

How to check if jQuery is Loaded

Tag: ,


You can do any stuff before loading jQuery, the following code will help you to find out jQuery loaded or not.This method is not limited to jQuery only, you can check for any other variable or function in your javascript.

if (typeof jQuery == 'undefined') {

    // jQuery IS NOT loaded, do stuff here.

}
If jquery doesn't loaded, load jquery using javascript
if(!window.jQuery)
{
   var script = document.createElement('script');
   script.type = "text/javascript";
   script.src = "path/to/jQuery";
   document.getElementsByTagName('head')[0].appendChild(script);
}

0 comments: