jquery - Remember toggle state on div after page refresh -


i have div expands/collapses automatic height based on button clicks. have working fine, use jquery.cookie.js remember if user expanded or not, stays open on page refresh. i've looked @ similar questions

e.g. keep toggle state on divs using cookie.js after page refresh

however can't seem work situation. it's not straight show/hide, , i'm having trouble figuring out syntax set , use cookie. here fiddle of working code, perhaps can me?

http://jsfiddle.net/j2rsy/

and here relevant code:

$('#viewless').hide(); $('#viewmore').click(function(){     var el = $('#resize01'),     curheight = el.height(),     autoheight = el.css('height', 'auto').height();     el.height(curheight).animate({height: autoheight}, 500);     $('#viewmore').toggle();     $('#viewless').toggle(); });  $('#viewless').click(function(){ $('#resize01').animate({height: '190'}, 500);     $('#viewmore').toggle();     $('#viewless').toggle(); }); 

try

$('#viewless').hide(); $('#viewmore').click(function(){     var el = $('#resize01'),         curheight = el.height(),         autoheight = el.css('height', 'auto').height();     el.height(curheight).animate({height: autoheight}, 500);     $('#viewmore').hide();     $('#viewless').show();      $.cookie('viewmore', true);  });  $('#viewless').click(function(){     $('#resize01').animate({height: '190'}, 500);     $('#viewmore').show();     $('#viewless').hide();      $.cookie('viewmore', false); });  if($.cookie('viewmore') == 'true'){     $('#viewmore').click(); } else {     $('#viewless').click(); } 

demo: fiddle


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -