I am new to php,i want to make my div to be closed even after refreshing.
my HTML code:
<div id="help_box" class="notification-page notification-info has-close-button">
<a href="javascript:void(0)" id="closehelp" title="Hide help" class="help-close float_right"></a>
div content
</div>
my JS code
$('#closehelp').click(function(){
$('#help_box').animate({ height:"hide", opacity:"hide", marginBottom:"-25px" },"slow");
});
On clicking close button my div hide,and if i refresh the page div appears.
How to hide it even if i refresh?? I searched for a long time but i cant progress.
use something like this==>
jQuery(document).ready(function(){ $('#help_box').toggle(); })
You have to use cookies to keep hide your div even after refreshing after clicking on close button.
When you click on close button,set a cookie with a expiry time(as long you do not want to show the div),as following
function setCookie(cname,cvalue,exdays)
{
var d = new Date();
d.setTime(d.getTime()+(exdays*24*60*60*1000));
var expires = "expires="+d.toGMTString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
$('#closehelp').click(function(){
$('#help_box').animate({ height:"hide", opacity:"hide", marginBottom:"-25px" },"slow");
setCookie('closediv',1,1);
});
//cookie will expire after one day
and then read the cookie in php.If cookie is available then keep the display:none of the div.
<?php $cookie=$_COOKIE['closediv'];?>
<div id="help_box" class="notification-page notification-info has-close-button" <?php if($cookie):?> style="display:none" <?php endif;?>>
<a href="javascript:void(0)" id="closehelp" title="Hide help" class="help-close float_right"></a>
div content
</div>