How to load raw CSS from Javascript?

View QuestionsCategory: CodeHow to load raw CSS from Javascript?
admin Staff asked 5 years ago
1 Answers
admin Staff answered 5 years ago
var cssId = 'myCss'; //search by Id if exist
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 = 'url to css file'; //put exact url here
    link.media = 'all';
    head.appendChild(link);
}

Credit: https://stackoverflow.com/questions/574944/how-to-load-up-css-files-using-javascript/46439433