Last active
August 26, 2018 03:17
-
-
Save simondahla/7d6698a73b689ad9bf1d9f2b63abdd62 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 adds style element to the bottom of the head element of the page | |
* @param {string} code Any string of css code | |
* @return {undefined} | |
*/ | |
function insertCssToHead( code ) { | |
var style = document.createElement('style'); | |
style.type = 'text/css'; | |
if (style.styleSheet) { | |
// IE | |
style.styleSheet.cssText = code; | |
} else { | |
// Other browsers | |
style.innerHTML = code; | |
} | |
document.getElementsByTagName('head')[0].appendChild( style ); | |
} | |
// Example usage; | |
// insertCssToHead('body{ background-color: red; }'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment