switch css file on button click in asp.net through jquery
Hi there i want to switch css of the page by clicking a button in asp.net, but somehow cant do that.
my code 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>

header section:

 

     <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 as day.css and night.css.
The page is using day.css and should switch to night.css on clicking of any button.

Interesting point is if i put .html file and both css files in a folder, it actually works.
But in visual studio i.e aspx page its not happening. I tried other jquery code like alert, its works fine.
i can improve my code after that by using toggle etc.
switch css file on button click in asp.net through jquery
===

Hi there i want to switch css of the page by clicking a button in asp.net, but somehow cant do that.
my code 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>

header section:

 

     <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 as day.css and night.css.
The page is using day.css and should switch to night.css on clicking of any button.

Interesting point is if i put .html file and both css files in a folder, it actually works.
But in visual studio i.e aspx page its not happening. I tried other jquery code like alert, its works fine.
i can improve my code after that by using toggle etc.