Last active
August 29, 2015 14:25
-
-
Save LucasArruda/11e80af1e141d96f4cfb to your computer and use it in GitHub Desktop.
Add CSS or JS on the fly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadCss(url) { | |
var link = document.createElement("link"); | |
link.type = "text/css"; | |
link.rel = "stylesheet"; | |
link.href = url; | |
document.getElementsByTagName("head")[0].appendChild(link); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadCssJquery(url) { | |
$('body').append('<link href="'+url+'" type="text/css" rel="stylesheet" />'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadJs(url) { | |
var script = document.createElement('script'); | |
script.src = url; | |
// script.onload = function () { /* do stuff on load */ }; | |
document.head.appendChild(script); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadJsJquery(url) { | |
$('body').append('<script src="'+url+'"></script>'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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