antk3
antk3

Reputation: 15

Why this jQuery cookie doesn't get retrieved?

I have this code for two divs acting like radio buttons, they behave well but the the cookie I set does not get retrieved on page refresh.

var isboxed = $.cookie('boxed_cookie');
if (isboxed = 'isboxed'){
  $('.wrap').addClass("boxed");
} else {
  $('.wrap').removeClass("boxed");
}

var selectors = $('#sbox-boxed-layout div');
selectors.on('click', function(e){
  var $this = $(this);
  selectors.removeClass('selected').addClass('disabled');
  $this.addClass('selected').removeClass('disabled');

  if ($('#sbox-boxed-layout div.on').hasClass('selected')){
    $('.wrap').addClass("boxed");
    $.cookie('boxed_cookie', 'isboxed' , { expires: 7, path: '/' });
  } else {
    $('.wrap').removeClass("boxed");
    $.cookie('boxed_cookie', 'isfull' , { expires: 7, path: '/' });
  }
});

Upvotes: 0

Views: 33

Answers (1)

Blazemonger
Blazemonger

Reputation: 92993

if (isboxed = 'isboxed'){ should use == (double-equals) for comparison.

Upvotes: 2

Related Questions