Is there a way to switch between bootstrap themes by clicking on a link with the theme name? Here is the HTML code snippet:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no, maximum-scale=1.0, user-scalable=no">
<title>Theme Changer</title>
<meta name="description" content="" />
<meta name="keywords" content="">
<link id="theme" rel="stylesheet" href="css/bootstrap.css" />
</head>
<body>
<nav class="navbar navbar-expand-sm bg-light navbar-light">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</nav>
<div class="row">
<div class="col-md-6">
<a id="Cyborg" href="" class="btn btn-block">Cyborg</a>
</div>
<div class="col-md-6">
<a id="Lux" href="" class="btn btn-block">Lux</a>
</div>
</div>
<footer>
<p>Theme Changer</p>
</footer>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script>
$(document).ready(function () {
$('#Cyborg').click(function () {
$('#theme').attr('href', 'css/bootstrapcyborg.css');
});
$('#Lux').click(function () {
$('#theme').attr('href', 'css/bootstraplux.css');
});
});
</script>
</body>
</html>
I've set up links for loading the initial CSS on page load and then dynamically changing the href
attribute upon clicking a link using jQuery. Can anyone point out any errors in my approach?