I have searched through many different methods to switch between different cascading style sheets, but have not been able to get any to work. I want to be able to have a sun button to link to the default style sheet and the moon button to link to the dark style sheet. Below are the pieces of my code that I have linking the style sheets and the buttons I want to link to those style sheets.
I know there are many questions like this, but I have tried them all and have not gotten them to work.
Thank you in advance.
<!-- Template Stylesheets -->
<link href="../assets/css/template/template.css" rel="stylesheet"
type="text/css" id="default">
<link href="../assets/css/template/template2.css" rel="alternate stylesheet"
type="text/css" id="dark">
<link href="../assets/css/template/bootstrap.min.css" rel="stylesheet">
<link href="../assets/css/template/navigation.css" rel="stylesheet">
<link id="pagestyle" rel="stylesheet" type="text/css" href="template.css">
<script type="text/javascript">
function swapStyleSheet(template){
document.getElementById('pagestyle').setAttribute('href', template);
}
</script>
<!-- Buttons in body to Switch -->
<li class="nav-item">
<a onclick="swapStyleSheet('template.css')" class="nav-link" href="#"><span data-feather="sun"></span></a>
</li>
<li class="nav-item">
<a onclick="swapStyleSheet('template2.css')" class="nav-link" href="#"><span data-feather="moon"></span></a>
</li>