View Full Version : Keep div hidden on different page
Dave Strider
02-22-2015, 07:07 AM
I currently have this code:
$(document).ready(function(){
$("#hide").click(function(){
$("#menu").hide(500);
});
$("#show").click(function(){
$("#menu").show(500);
});
});
What I would like to do is for it to remember the users selection. Essentially if the user is on the home page and chooses to hide the menu, it will stay hidden while they are on a different page.
Dr.CustUmz
02-22-2015, 08:33 AM
what you need is an Oreo =)
take a look at this, seems you understand what you're doing. So im going to point you in the right direction
Double Stuffed Oreo's (http://runnable.com/Ul1vNvQdOWU1AADA/basic-usage-of-jquery-cookie-js-for-javascript)
Chocolate Chip Cookies (http://www.sitepoint.com/eat-those-cookies-with-jquery/)
Dave Strider
02-22-2015, 11:13 PM
what you need is an Oreo =)
take a look at this, seems you understand what you're doing. So im going to point you in the right direction
Double Stuffed Oreo's (http://runnable.com/Ul1vNvQdOWU1AADA/basic-usage-of-jquery-cookie-js-for-javascript)
Chocolate Chip Cookies (http://www.sitepoint.com/eat-those-cookies-with-jquery/)
I have no clue what I'm doing with jQuery. I found this code online lol.
greigeh
02-23-2015, 03:50 PM
Here is something what you're looking for, I use this on my forum as an alternative to the confusing templates that is used within vB3. You can alter this to suit your needs
$(document).ready(function() {
// LEFT COLUMN:
// When the collapse button is clicked:
$('.collapseLeft_20').click(function() {
$('.collapseLeft_20').css("display","none");
$('.expandLeft_20').css("display","block");
$('#leftCol_20').css("display","none");
$.cookie('leftCol_20', 'collapsed');
});
// When the expand button is clicked:
$('.expandLeft_20').click(function() {
$('.expandLeft_20').css("display","none");
$('.collapseLeft_20').css("display","block");
$('#leftCol_20').css("display","block");
$.cookie('leftCol_20', 'expanded');
});
// COOKIES
// Left column state
var leftCol_20 = $.cookie('leftCol_20');
// Set the user's selection for the left column
if (leftCol_20 == 'collapsed') {
$('.collapseLeft_20').css("display","none");
$('.expandLeft_20').css("display","block");
$('#leftCol_20').css("display","none");
};
});
Dave Strider
02-24-2015, 02:08 AM
Here is something what you're looking for, I use this on my forum as an alternative to the confusing templates that is used within vB3. You can alter this to suit your needs
$(document).ready(function() {
// LEFT COLUMN:
// When the collapse button is clicked:
$('.collapseLeft_20').click(function() {
$('.collapseLeft_20').css("display","none");
$('.expandLeft_20').css("display","block");
$('#leftCol_20').css("display","none");
$.cookie('leftCol_20', 'collapsed');
});
// When the expand button is clicked:
$('.expandLeft_20').click(function() {
$('.expandLeft_20').css("display","none");
$('.collapseLeft_20').css("display","block");
$('#leftCol_20').css("display","block");
$.cookie('leftCol_20', 'expanded');
});
// COOKIES
// Left column state
var leftCol_20 = $.cookie('leftCol_20');
// Set the user's selection for the left column
if (leftCol_20 == 'collapsed') {
$('.collapseLeft_20').css("display","none");
$('.expandLeft_20').css("display","block");
$('#leftCol_20').css("display","none");
};
});
It still appears when going to a new page even if it was hidden on the previous one.
Dr.CustUmz
02-24-2015, 07:01 AM
did you modify it to fit your classes? take the time to read the links i shared, get an understanding of what you're trying to accomplish, you should have no issue adapting grieg's code.
http://stackoverflow.com/questions/1458724/how-to-set-unset-cookie-with-jquery
if your looking more for a "will you do it for me" and not actually wanting to learn anything, share your template
Dave Strider
02-24-2015, 10:49 AM
did you modify it to fit your classes? take the time to read the links i shared, get an understanding of what you're trying to accomplish, you should have no issue adapting grieg's code.
http://stackoverflow.com/questions/1458724/how-to-set-unset-cookie-with-jquery
if your looking more for a "will you do it for me" and not actually wanting to learn anything, share your template
Well I just solved the issue. I forgot to include jquery.cookie.js file. I probably should have double checked to see if that was included. Honest mistake really. Thanks for the help!
greigeh
02-24-2015, 07:35 PM
Sorry I should really have mentioned you needed that file! Glad you got it to work though. :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.