I want to switch CSS pages by clicking a button in asp.net, but somehow I canβt do this. My code is as follows:
HTML:
<div> <h1>My Website</h1> <br/> <button>Night Mode</button> <button>Day Mode</button> </div>
Script:
<script> $(function () { $('button').click(function () { $('link').attr('href', 'Styles/night.css'); }); }); </script>
Title:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <link href="Styles/day.css" rel="stylesheet" type="text/css" />
I have 2 css files in Styles folder like day.css and night.css. The page uses day.css and should switch to night.css when any button is pressed.
If I put the .html file and both .css files in a folder, it really works. But in Visual Studio (e.g. aspx page) this does not happen. I tried using other jQuery code like alert , it works fine. I can improve my code after that using a switch, etc.
source share