Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add CSS or JS on the fly
function loadCss(url) {
var link = document.createElement("link");
link.type = "text/css";
link.rel = "stylesheet";
link.href = url;
document.getElementsByTagName("head")[0].appendChild(link);
}
function loadCssJquery(url) {
$('body').append('<link href="'+url+'" type="text/css" rel="stylesheet" />');
}
function loadJs(url) {
var script = document.createElement('script');
script.src = url;
// script.onload = function () { /* do stuff on load */ };
document.head.appendChild(script);
}
function loadJsJquery(url) {
$('body').append('<script src="'+url+'"></script>');
}
// Loads jQuery if not present
!window.jQuery && loadJs('https://code.jquery.com/jquery-latest.min.js');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.