I'm using this code to activate disactivate the contents of fieldsets and jquery cookies plugin which works except for the state of the legend which always comes back as unselected which in turn sets the elements inside the fieldset to disabled.
function activeLegend(){
var legendId=this.id
var fsId=$(this).closest('fieldset').prop('id')
var inputs=$('#'+fsId).find(':input')
inputs.each(function(){
if ($(this).is(':disabled')){
$('#'+legendId).css('background-color', '#6b0000');
$('#'+fsId+' :input').prop('disabled', false);
$('#'+fsId+' input:checkbox').button('enable');
$('#'+fsId+' input:radio').button('enable');
return false;
}else{
$('#'+legendId).css('background-color', '#b20000');
$('#'+fsId+' :input').prop('disabled', true);
$('#'+fsId+' input:checkbox').button('disable');
$('#'+fsId+' input:radio').button('disable');
return false;
};
});
};
How can I set a cookie to remember the state of the Legend?
EDIT:
I'm close, I'm able to get the Legend 'state' by checking for it's background color... but I can't set the cookie to remember the color so it always reverts back to it's original state... what am I doing wrong?
$(function(){
var legend=$('.setCookies').find('.activeLegend');
legend.each(function(){
$(this).css('background-color', $.cookie(this.id));
});
legend.click(function(){
var fsId=$(this).closest('fieldset').prop('id')
var legendId=this.id
if ($('#'+legendId).css('background-color')=='rgb(178, 0, 0)'){
$('#'+legendId).css('background-color', '#6b0000');
$('#'+fsId+' :input').prop('disabled', true);
$('#'+fsId+' input:checkbox').button('disable');
$('#'+fsId+' input:radio').button('disable');
$.removeCookie(this.id);
}else{
$('#'+legendId).css('background-color', '#b20000');
$('#'+fsId+' :input').prop('disabled', false);
$('#'+fsId+' input:checkbox').button('enable');
$('#'+fsId+' input:radio').button('enable');
$.cookie(this.id, {expires: 365});
}
});
});