Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8201527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:50:43+00:00 2026-06-07T06:50:43+00:00

I have a single button that I want to add functionality to. When you

  • 0

I have a single button that I want to add functionality to. When you click on the button the style of the site will change into a high-contrast version (i.e. the stylesheet high_contrast.css gets appended to the head). Obviously I’m doing a few things wrong as the code below just switches the style for the current page and when you navigate to another page it switches back to the default style. I probably shouldn’t be setting that variable highContrast every time. I’d like to use query cookie plugin (https://github.com/carhartl/jquery-cookie) to accomplish this but don’t really understand how to use it in this case.

This is the HTML

<div id="contrast-btn"><a href="#" rel="css/high-contrast.css">high contrast</a></div>

This is the script

$(document).ready(function(){
    var highContrast = false;
    $("#contrast-btn a").click(function () {
        if (!(highContrast)) {
            $('head').append('<link rel="stylesheet" href="css/high-contrast.css" type="text/css" id="hc_stylesheet"/>');
            highContrast = true;
        }       
        else {
            // remove the high-contrast style
            $("#hc_stylesheet").remove();
            highContrast = false;
        }
    });
});

Thanks for your help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:50:44+00:00Added an answer on June 7, 2026 at 6:50 am

    You have to get and set the value via the cookie:

    $(document).ready(function(){
    // DRY wrapper function
    function appendStyleSheet() {
      $('head').append('<link rel="stylesheet" href="css/high-contrast.css" type="text/css" id="hc_stylesheet"/>'); 
    }
    // append the style sheet on load if the cookie is set to true
    if ($.cookie('high_contrast') == 'true') {
      appendStyleSheet();      
    }
    $("#contrast-btn a").click(function () {
        if ($.cookie('high_contrast') != 'true') {
    
            appendStyleSheet();      
            $.cookie('high_contrast', 'true'); // set the cookie to true
        }       
        else {
            // remove the high-contrast style
            $("#hc_stylesheet").remove();
            $.cookie('high_contrast', 'false');
        }
    });
    });
    

    You can add options like expiration or site-wide validity to the cookie, so if you want the cookie to be valid for a year, add this to the cookie command

    $.cookie('high_contrast', 'false', {expires: 365});
    

    If you want it to be valid across your whole domain, which may be most likely the case for your implementation, you can add path ‘/’:

    $.cookie('high_contrast', 'false', {path: '/'});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a table with single row (textfield) and Add Row button, when user
Let's say I have a button.. how can I distinguish between single click and
I have some javascript click handlers that don't do what I want in IE8.
I have a page which contains several forms. I want to add a single
I want to make a single page website and it will have huge content.
In my app, I want to have a single background image that I use
I have a simple form with a single button and a datatable with a
I have a small data collection app which has a single button to start
i have a single filed which i need to clone with a clone button
Assume we have a single Windows form with a button called SimpleButton1. The following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.