Reputation: 1
I'm using carhartl / jquery-cookie plugin. I'm looking for solution how to hide the same divs in few pages in my domain. On first visit div1 should be show and div2 hide on next visits div2 show and div1 hide. The same action should work for every pages. But my code work only on first visit for first page if another page is open script show div2 and hide div1 I'm not familiar with cookie and jquery can anybody help ?
$(document).ready(function() {
var visited = $.cookie('visited')
if (visited == null) {
$('.div1').show();
$('.div2').hide(); ``
} else {
$('.div1').hide();
$('.div2').show();
}
$.cookie('visited', 'yes_visited', { expires: 1 });
});
Upvotes: 0
Views: 926
Reputation: 388316
If you want to share the cookie across multiple pages then try
$(document).ready(function () {
var visited = $.cookie('visited')
if (visited == null) {
$('.div1').show();
$('.div2').hide();
} else {
$('.div1').hide();
$('.div2').show();
}
$.cookie('visited', 'yes_visited', {
expires: 1,
path: '/'
});
});
Demo: Fiddle, another version
Upvotes: 1