user991830 user991830 - 2 years ago 316
Javascript Question

jQuery to remove div & set cookie to never show again

I am using the following html / jQuery to remove a div after clicking a link.

When clicking the link, I also need to set a cookie that keeps the div as 'removed' when the same visitor comes back to the site.


<div id="close-me">
bye bye - being removed on click of close link

<a href="#" class="close-div">Close</a>


jQuery(document).ready(function( $ ) {

I would assume jquery.cookie.js is the best solution.

How would I do this?

JSfiddle here

Answer Source

jQuery Cookie is no longer maintened, so I would not go for it. Instead, you can use js-cookie which is recommended as replacement by the dev team of jQuery Cookie.

Once loaded, it will be :

jQuery(document).ready(function($) {
    if (typeof Cookies.get('hide-div') !== 'undefinied') {

    $(".close-button").click(function() {
        Cookies.set('hide-div', true);
<script src=""></script>
<script src=""></script>

<div id="close-me">
  <i class="close-button">&times;</i>
  Your content here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download