Skip to content

Instantly share code, notes, and snippets.

@ianaya89
Created December 29, 2014 19:45
Show Gist options
  • Save ianaya89/3aedf3308603135bf69b to your computer and use it in GitHub Desktop.
Save ianaya89/3aedf3308603135bf69b to your computer and use it in GitHub Desktop.
Add jQuery to any page that does not have it already.
(function() {
if ( !window.jQuery ) {
var $inUse = !!window.$,
script = document.createElement('script');
script.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js');
script.addEventListener('load', function(){
console.log('jQuery was loaded.');
if ($inUse) {
jQuery.noConflict();
console.log('jQuery was loaded in noConflict mode, use jQuery instead \'$\' ');
}
});
document.body.appendChild(s);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment