Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Sanix-Darker/6feb114deec64ac1bbc8242f8dd12d9b to your computer and use it in GitHub Desktop.
Save Sanix-Darker/6feb114deec64ac1bbc8242f8dd12d9b to your computer and use it in GitHub Desktop.
[JS] How to check if jQuery is not already, loaded and call it
function myJQueryCode() {
//Do stuff with jQuery
}
if(typeof jQuery=='undefined') {
var headTag = document.getElementsByTagName("head")[0];
var jqTag = document.createElement('script');
jqTag.type = 'text/javascript';
jqTag.src = 'jquery.js';
jqTag.onload = myJQueryCode;
headTag.appendChild(jqTag);
} else {
myJQueryCode();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment