Using jQuery cookie.js to remember hide/show element?

…衆ロ難τιáo~ 提交于 2019-12-04 07:52:24

Should be pretty easy. When you show the div add some code like:

jQuery.cookie('show_desc', 'yep');

...and when you hide the div:

jQuery.cookie('show_desc', 'nope');

...and then at the top of your code where you've got:

jQuery('#group_desciption').hide();

...change it to:

var shouldShow = jQuery.cookie('show_desc') == 'yep';
if( shouldShow ) { jQuery('#group_desciption').show(); }
else {             jQuery('#group_desciption').hide(); }

Or, alternatively:

jQuery('#group_desciption')[jQuery.cookie('show_desc') == 'yep' ? 'show' : 'hide']();

:)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!