Search code examples
javascriptjquerydhtml

not able to set a cookie using jquery


I am trying to set a cookie using the following code using jquery and qtip. As you can see, when this 'beforeShow' event is triggered I need to set a cookie. I can confirm the event is being triggered as I see the alert although I'm not able to see the cookie being set? Should this code work or am I missing something?
Many thanks,

        api: {
            beforeShow: function() {
                if(document.getElementById('CheckMessage')) {
                    alert("");
                    $.cookie("MyTestExampleCookie", "1");
                    return false;
                }
            }
        },

Solution

  • document.cookie = ("MyTestExampleCookie=1");
    

    though it's more advisable to use some cookie lib