Last active
January 2, 2016 14:48
-
-
Save yratof/8318750 to your computer and use it in GitHub Desktop.
add class to body on click.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<span class="font-size" href="#">Font Size</span> | |
<span class="black-white" href="#">Black and White</span > | |
<script src="<?php bloginfo('template_url'); ?>/library/js/libs/cooked.js"></script> | |
<script> | |
jQuery(document).ready(function($){ | |
// Check (onLoad) if the cookie is there and set the class if it is | |
if ($.cookie('font-size') == "yes") {$("body").addClass("font-size");} | |
if ($.cookie('black-white') == "yes") { $("body").addClass("black-white");} | |
// When the span is clicked | |
$(".font-size").click(function () { | |
// Check the current cookie value | |
// If the cookie is empty or set to no, then add font-size | |
if ($.cookie('font-size') == "undefined" || $.cookie('font-size') == "no") { | |
// Set cookie value to yes | |
$.cookie('font-size','yes', {expires: 7}); | |
// Add the class to the body | |
$("body").addClass("font-size"); | |
} | |
// If the cookie was already set to yes then remove it | |
else { | |
$.cookie('font-size','no', {expires: 7}); | |
$("body").removeClass("font-size"); | |
} | |
}); | |
// When the span is clicked | |
$(".black-white").click(function () { | |
// Check the current cookie value | |
// If the cookie is empty or set to no, then add black-white | |
if ($.cookie('black-white') == "undefined" || $.cookie('black-white') == "no") { | |
// Set cookie value to yes | |
$.cookie('black-white','yes', {expires: 7}); | |
// Add the class to the body | |
$("body").addClass("black-white"); | |
} | |
// If the cookie was already set to yes then remove it | |
else { | |
$.cookie('black-white','no', {expires: 7}); | |
$("body").removeClass("black-white"); | |
} | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment