×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Mojito Joe
Added: Jan 31, 2013 8:46 PM
Views: 14
Tags: jquery
This snippet checks if jQuery is loaded and show its version. If it's not available it loads it (useful for plugins for instance).
  1. if (typeof jQuery == 'undefined') {
  2.    var head = document.getElementsByTagName('head')[0];
  3.    script = document.createElement('script');
  4.    script.id = 'jQuery';
  5.    script.type = 'text/javascript';
  6.    script.src = '//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js';
  7.    head.appendChild(script);
  8.    alert('Unable to detect jquery\nwill load it...\nDone!');
  9. } else {
  10.    alert('jQuery v' + $().jquery + ' available!');
  11. }