Lignes de code HTML

Javascript – How to add jQuery from a Javascript file

When you create a javascript file, you may want to make sure you can use jQuery. To avoid having it twice and maybe introducing incompatibilities, just add this at the beginning of the javascript file:

if (typeof jQuery 'undefined')
   var script - document.createElement ('script');
   script.src - 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js';
   script.type - 'text/javascript';
   document.getElementsByTagName ('head')[0].appendChild (script);
}

Leave a comment