PHP_USER1
PHP_USER1

Reputation: 628

use of cookies in javascript

<div id="cookierr" class="cook"><a href="" style="text-decoration:none; color:#ffffff">This site uses cookies Learn more</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I understand Hide this message <img src="<?=$img_loc?>abc.png" style="margin-bottom:-4px; cursor:pointer;" class="cross"/></div>

        <script>
         $(function() {
          $(".cross").on("click", function(){
            $(".cook").remove();
            $.cookie('cook', '1', { expires: 365, path: '/' });
          });
        });
        </script>

In my site this is a div when u click on the abc.png ie cross button . the whole div is removed and i am saving it a cookie so that the user never see this again . but the cookie part is showing me the error . am i doing something wrong plz help me

Upvotes: 0

Views: 64

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388446

From the error it is clear that the cookie plugin is not added to the page.

Add it using CDNJS

<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.0/jquery.cookie.js"‌​></script>

Or download the script file from the plugin site and include it in your page

Also you may have to add code to remove it on page load if the cookie is already set

$(function () {
    var cookie = $.cookie('cook');
    if (cookie) {
        $(".cook").remove();
    } else {
        $(".cross").on("click", function () {
            $(".cook").remove();
            $.cookie('cook', '1', {
                expires: 365,
                path: '/'
            });
        });
    }
});

Demo: Fiddle

Upvotes: 1

Related Questions