if (!$.cookie('alert')) { $( ".announcement" ).show(); $(".close").click(function() { $( ".announcement" ).fadeOut( "slow" ); // set the cookie for 24 hours var date = new Date(); var minutes = 1; date.setTime(date.getTime() + (minutes * 60 * 1000)); $.cookie('alert', true, { expires: date }); }); }
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script> <script type="text/javascript" src="http://localhost/forob/jscripts/jquery.cookie.js"></script> <div class="announcement bg">Announcement <a class="close" href="#">X</a></div>
.announcement { display: none; } .bg { background: rgb(120, 120, 121); padding: 5px; width: 125px; overflow: hidden; font-family: arial; } .close{ text-decoration: none; margin-left: 5px; margin-top: -4px; } a:link, a:active, a:hover, a:visited{ text-decoration: none; color: black; font-family: arial; }