jQuery toggle of classes and toggle the cookie value?
Is there a possible way to toggle the cookie like my example below? I used to have two buttons but would like to just use one and toggles.
$("#text-change").click(function() {
$("body").toggleClass("large");
$(this).toggleClass("large");
// Here I want to toggle the cookie value
$.cookie("textSize", "large", {expires: 365});
$.cookie("textSize", "small", {expires: 365});
return false;
});
//then I can the check cookie throughout the site
if($.cookie("textSize") != "large") {
$("#text-smaller").addClass("disabled");
$("body").removeClass("large");
}
else {
$("#text-larger").addClass("disable开发者_如何学编程d");
$("body").addClass("large");
}
$("#text-change").click(function() {
$("body").toggleClass("large");
$(this).toggleClass("large");
// Here I want to toggle the cookie value
if ($(this).hasClass("large")){
$.cookie("textSize", "large", {expires: 365});
}else{
$.cookie("textSize", "small", {expires: 365});
}
return false;
});
Even more simpler
$("#text-change").click(function() {
$("body").add(this).toggleClass("large");
// Here I want to toggle the cookie value
$.cookie("textSize", $(this).hasClass("large")?"large":"small", {expires: 365});
return false;
});
精彩评论