Dynamic jQuery Library loading when jQuery is undefined

Hi Guyz,

Quick Post on loading jQuery library when it is undefined.

Add following snippet on top of the script:

if (typeof(jQuery) == 'undefined') {
   var jq = document.createElement("script");
   jq.type = "text/javascript";
   jq.src = "http://code.jquery.com/jquery-1.9.0.js";
   document.getElementsByTagName('head')[0].appendChild(jq);
}

This will load the jQuery from CDN of Google.

Blog more, Help more..!

Cheers!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s