• Resolved sarangsss29

    (@sarangsss29)


    How can I use the following code using Code snippet?
    I can use the jQuery code with other plugins like Simple Custom CSS and JS
    However, it throws error when I try to use it via Code Snippet. I don’t want to use a new plugin because I already have several code snippets implemented.

    How can I add this code?

    jQuery(document).ready(function($) {
        /*Click on dark mode icon. Add dark mode classes and wrappers. 
        Store user preference through sessions*/
        $('.wpnm-button').click(function() {
            //Show either moon or sun
            $('.wpnm-button').toggleClass('active');
            //If dark mode is selected
            if ($('.wpnm-button').hasClass('active')) {
                //Add dark mode class to the body
                $('body').addClass('dark-mode');
                //Save user preference to Storage
                localStorage.setItem('darkMode', true);
            } else {
                $('body').removeClass('dark-mode');
                localStorage.removeItem('darkMode');
            }
        })
        //Check Storage. Display user preference 
        if (localStorage.getItem("darkMode")) {
            $('body').addClass('dark-mode');
            $('.wpnm-button').addClass('active');
        }
    })
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘jQuery code not working with Code Snippet’ is closed to new replies.