jqueryjquery-uijquery-cookietypeerror

Uncaught TypeError: $.cookie is not a function for Dialog


I noticed that my jQuery dialog box no longer saves a cookie and continues to pop up each page reload. I'm not sure what changed as this was working great for nearly 1 year. I grabbed a fresh copy of jQuery UI and js Cookie but I can't figure out why I'm getting the error:

Uncaught TypeError: $.cookie is not a function.

Does something need to be updated in my jQuery?

<script src="<?php echo get_template_directory_uri(); ?>/jquery-ui.js"></script>
<script src="<?php echo get_template_directory_uri(); ?>/js.cookie.js"></script>
<script type="text/javascript">
( function($) {
$(document).ready(function() {
    $(function() {
        if( document.cookie.indexOf( "shipping_note" ) < 0 ) {
            $( ".shipping-note-container" ).dialog({
                modal: true,
                resizable: false,
                show: 'slide',
                buttons: {
                    Ok: function() {
                        $( this ).dialog( "close" );
                        $.cookie('shipping_note', 'Ok', { path: '/', expires: 7 });
                    }
                }
            });
        }
    });
});
} ) ( jQuery );


Solution

  • If you are using the js js-cookie library the methods are:

    Cookies.set('name', 'value');
    Cookies.get('name');
    .....
    

    Instead if you want to use the jQuery plugin you need to download it locally and then you can use it as:

    $.cookie("example", "foo");