javascript - I 'm storring a value in localstorage and trying to use it in an if statement but i get only null, i have stringify the value too -
this set value localstorage. data-rel after click , pass localstorage stringified.
var selectedclass = ""; var firstclass = ""; $(".months a").click(function(){ firstclass = $(this).attr("data-rel"); localstorage.setitem("firstclass ", json.stringify(firstclass) ); });
this value localstorage.
var check = ""; var test2 = localstorage.getitem("firstclass"); check = json.parse(test2);
and here when try use returns null script never runs else.
if (check === null) { selectedclass = ""; $(".fil-cat").click(function(){ selectedclass = $(this).attr("data-rel"); $("#produstswide").fadeto(100, 0.1); $("#produstswide div.fluid- conteiner").not("."+selectedclass).fadeout().removeclass('scale-anm'); settimeout(function() { $("."+selectedclass).fadein().addclass('scale-anm'); $("#produstswide").fadeto(300, 1); }, 300); }); } else { selectedclass = check; $("#produstswide").fadeto(100, 0.1); $("#produstswide div.fluid- conteiner").not("."+selectedclass).fadeout().removeclass('scale-anm'); settimeout(function() { $("."+selectedclass).fadein().addclass('scale-anm'); $("#produstswide").fadeto(300, 1); }, 300); localstorage.clear(); }
there white space in key string use set value
localstorage.setitem("firstclass ", json.stringify(firstclass) );
try removing it
localstorage.setitem("firstclass", json.stringify(firstclass) );
Comments
Post a Comment