Queries and SolutionsCategory: HtmlHow we can change our stylesheet path using javascript?
bestonetechnologies Staff asked 8 years ago

How we can change our stylesheet path using javascript?

0 Answers
bestonetechnologies Staff answered 8 years ago

Below is the example to change path of stylesheet:
I have 2 stylesheet (blue.css, green.css) in the same folder in which my html file is.
Code in blue.css:
body{ background:blue; }
Code in green.css:
body{ background:green; }
Main html file Code:
<html>
<head>
<link type=”text/css” rel=”stylesheet” media=”all” href=”green.css” id=”my_theme_css” />
<script>
function changeTheme(theme) {
document.getElementById(‘my_theme_css’).href = theme + ‘.css’;
}
</script>
</head>
<body>
<p>Testing themes.</p>
<input type=”button” id=”btnTheme” name=”btnTheme” value=”Green” onClick=”changeTheme(‘green’)”/>
<input type=”button” id=”btnTheme” name=”btnTheme” value=”Blue” onClick=”changeTheme(‘blue’)”/>
</body>
</html>

Your Answer

16 + 14 =