I have a html + css + javascript application.
I want to be able to enable theming.
All my css are replicated in two folders: /theme1/… and /theme2/…
So my html looks like:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="theme1/file1.css"/>
<link rel="stylesheet" href="theme1/file2.css"/>
....
....
</head>
<body>
.....
</body>
</html>
I want to be able to change using javascript the home folder of the css (theme1 to theme2).
Any ideas?
Here is what you will need to solve the problem:
linktag withrel="stylesheet"will probably do, but you can even go so far as to specify “starting withtheme1” if you want. This can all be done withdocument.querySelectorAll("link[rel=stylesheet][href^=theme1]")forloop will do nicely.getAttribute("href")gets the string you need.replace()will allow you to replace the part of the string you want.setAttribute("href",newattr)will put the attribute back into the tag.