I want css path in the head section of an HTMl page, the path should come through an external JS file as I want to add multiple no. of css.
1 Answer
function addCSS() {
var headtg = document.getElementsByTagName('head')[0];
if (!headtg) {
return;
}
var linktg = document.createElement('link');
linktg.type = 'text/css';
linktg.rel = 'stylesheet';
linktg.href = 'CSS/RoundCorners.css';
linktg.title = 'Rounded Corners';
headtg.appendChild(linktg);
}
Source: http://www.devcurry.com/2009/07/how-to-add-css-link-programmatically.html
2 Comments
amolD
Thanks a lot :) ... Is there any way to use multiple css so I can change the theme. Actually I was looking for the theme changes through css based JS but I stuck on the 1st step which is now solved as u help me...Thank you once again.
Curtis
@amolD You'd have to change an existing
link element rather than append a new one. CoDe ADDict has already posted a link for switching stylesheets cssnewbie.com/simple-jquery-stylesheet-switcher