Learn free online HTML5, javascript, and jquery Tutorials by Examples

Sunday, 12 January 2020

load multiple stylesheet using javascript

var loadMultipleCss = function(){
//load local stylesheet
loadCss('https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css');
loadCss('https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.css');
}
var loadCss = function(cssPath){
var cssLink = document.createElement('link');
cssLink.rel = 'stylesheet';
cssLink.href = cssPath;
var head = document.getElementsByTagName('title')[0];
head.parentNode.insertBefore(cssLink, head);
};
window.addEventListener('load', loadMultipleCss);
-----------------------------------------------------------------------------------

/* Link First CSS File */
var giftofspeed = document.createElement('link');
giftofspeed.rel = 'stylesheet';
giftofspeed.href = 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css';
giftofspeed.type = 'text/css';
var godefer = document.getElementsByTagName('link')[0];
godefer.parentNode.insertBefore(giftofspeed, godefer);

No comments:

Post a Comment