jQuery cookie not working properly in wordpress

Ok,

I solve this with the help of @TheDeadMedic’s help. I use wordpress cookiepath constant and it works on wordpress perfectly.

Here is the jquery code:

jQuery(document).ready(function () {
                // baking cookie ;p
                function set_cookie(ID) {
                    document.cookie = ID + "=opened; path=<?php echo COOKIEPATH ?>";
                }

                // getting it out from the oven... 
                function get_cookies_array() {
                    var cookies = {};

                    if (document.cookie && document.cookie != '') {
                        var split = document.cookie.split(';');
                        for (var i = 0; i < split.length; i++) {
                            var name_value = split[i].split("=");
                            name_value[0] = name_value[0].replace(/^ /, '');
                            cookies[decodeURIComponent(name_value[0])] = decodeURIComponent(name_value[1]);
                        }
                    }
                    return cookies;
                }

                // yuck... sorry i don't know how to cook :S
                function unset_cookie(cookie_name) {
                    var cookie_date = new Date();
                    cookie_date.setTime(cookie_date.getTime() - 1);
                    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString() + "; path=<?php echo COOKIEPATH ?>";
                }

                var tree_id = 0;
                jQuery('ul.wpc-categories li:has(ul)').addClass('has-child').prepend('<span class="switch"><img src="https://wordpress.stackexchange.com/questions/184411/<?php echo plugin_dir_url(__FILE__); ?>/includes/css/images/icon-plus.png" /></span>').each(function () {
                    tree_id++;
                    jQuery(this).attr('id', 'tree' + tree_id);
                });

                jQuery('ul.wpc-categories li > span.switch').click(function () {
                    var tree_id = jQuery(this).parent().attr('id');
                    if (jQuery(this).hasClass('open')) {
                        jQuery(this).parent().find('ul:first').slideUp('fast');
                        jQuery(this).removeClass('open');
                        jQuery(this).html('<img src="https://wordpress.stackexchange.com/questions/184411/<?php echo plugin_dir_url(__FILE__); ?>/includes/css/images/icon-plus.png" />');
                        unset_cookie(tree_id)
                    } else {
                        jQuery(this).parent().find('ul:first').slideDown('fast');
                        jQuery(this).html('<img src="<?php echo plugin_dir_url(__FILE__); ?>/includes/css/images/icon-minus.png" />');
                        jQuery(this).addClass('open');
                        set_cookie(tree_id)
                    }
                });

                var cookies = get_cookies_array();
                for (var name in cookies) {
                    jQuery('#' + name).find('> ul').css({'display' : 'block'});
                    jQuery('#' + name).find('> span').addClass('open').html('<img src="<?php echo plugin_dir_url(__FILE__); ?>/includes/css/images/icon-minus.png" />');
                }
            });