How to load raw CSS from Javascript?

View QuestionsCategory: CodeHow to load raw CSS from Javascript?
admin Staff asked 6 months ago
1 Answers
admin Staff answered 6 months 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