I need help adding functionality to a single button on my site. My goal is to switch the style of the site to a high contrast version when the button is clicked (by appending the high_contrast.css stylesheet to the head). Currently, my code only changes the style for the current page and reverts back to the default style when navigating to another page. I believe the issue lies in me setting the variable highContrast every time. I would like to incorporate the query cookie plugin (https://github.com/carhartl/jquery-cookie) but am unsure how to implement it in this scenario.
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;
}
});
});
Any assistance is greatly appreciated. Thank you!