Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Have the following code, trying to get it to take and stay on the night or day mode depending what is clicked for the whole site or if page is refreshed
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Day And Night Mode</title>
    <link rel="stylesheet" href="style.css" type="text/css">
</head>

<body>
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: sans-serif;
        }

        section {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100vh;
            box-sizing: border-box;
            padding: 100px;
            transition: 0.5s;
        }

        section.dark {
            background: #262626;
            color: #fff;
        }

        ul {
            position: absolute;
            top: 20px;
            right: 20px;
            margin: 0;
            padding: 0;
            width: 100px;
            height: 30px;
            z-index: 1;
            border: 1px solid #000;
            border-radius: 4px;
            cursor: pointer;
            overflow: hidden;
        }

        ul.active {
            border-color: #fff;
        }

        ul li {
            list-style: none;
            width: 100%;
            height: 60px;
            text-align: center;
            text-transform: uppercase;
            transition: 0.5s;
        }

        ul.active li {
            transform: translateY(-30px);
        }

        ul li span {
            display: block;
            width: 100%;
            height: 30px;
            line-height: 30px;
            color: #262626;
            background: #fff;
        }

        ul li span:nth-child(1) {
            background: #262626;
            color: #fff;
        }

    </style>

    <section>
        <h1>What is Lorem ipsum ?</h1>
        <p>"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
        <p>"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
        <p>"On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains."</p>
    </section>
    <ul>
        <li>
            <span>Night</span>
            <span>Light</span>
        </li>
    </ul>
    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $('ul').click(function() {
                $('ul').toggleClass('active')
                $('section').toggleClass('dark')
            })
        })

    </script>
</body>

</html>


What I have tried:

tried playing with the java but not able to figure it out to hold settings for refresh and or the whole site depending what mode your in thanks in advance
Posted
Comments
Afzaal Ahmad Zeeshan 25-Aug-18 19:34pm    
Do you want to persist the state of the application, in dark or light mode?
Reddog2 26-Aug-18 12:22pm    
I am wanting to take and have the thing set to where if someone clicks the Night button, and goes to another page on the site that it takes and holds the Dark mode OR if the night mode is clicked and the page is refreshed why in the night mode it holds the night mode on refresh. Hope this helps. I had seen on some websites when i googled it of some people sying something about Onload command etc ???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900