how to load css file in javascript code example
Example 1: link stylesheet in javascript
var cssId = 'myCss';
if (!document.getElementById(cssId))
{
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.id = cssId;
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'http://website.com/css/stylesheet.css';
link.media = 'all';
head.appendChild(link);
}
Example 2: append css file with javascript
var cssFile = document.createElement('link');
cssLink1.rel = 'stylesheet';
cssLink1.href = "styles.css";
document.head.appendChild(cssFile);