Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$.cookie is not a function

When I try to load my page that uses jquery, when the following line is hit:

if ($.cookie('compare') != null)  

I get the error $.cookie is not a function. Has anybody seen this before?

like image 934
Introgy Avatar asked Oct 27 '10 14:10

Introgy


People also ask

What is cookie in JavaScript?

Cookies are data, stored in small text files, on your computer. When a web server has sent a web page to a browser, the connection is shut down, and the server forgets everything about the user.

How to manage Cookies in JavaScript?

This function uses JavaScript's string split method to split the cookie string by semi-colons. Then it loops through the result array of strings and splits them again by "=" producing the cookie key/value pair. Then it simply tests the cookie key (c[0]) against the name of the cookie you are trying to read.

How to change the value of a cookie in JavaScript?

To update a cookie, simply overwrite its value in the cookie object. You do this by setting a new cookie on the document with the same Name, but a different Value.

How to remove cookie JavaScript?

You can use setCookie('name', 'value', 0) to delete a cookie.


1 Answers

That means that the $.cookie plugin isn't being included in the page, at least not being it's getting called. Make sure it's both being included, and is being included before it's getting used. Include it just after jQuery itself to be safe.

Just a tip: Several other plugins rely on the cookie plugin (but don't necessarily check if it exists before calling it), you could be using one.

like image 115
Nick Craver Avatar answered Oct 15 '22 00:10

Nick Craver