admin管理员组

文章数量:1313001

I can't figure out why I'm getting this simple error in the console:

Uncaught TypeError: $.cookie is not a function

Here is where I implement JavaScript and jQuery:

<script src="jquery.js"></script>
<script src="cookies.js"></script>
<script src="scripts/changeTheme.js"></script>
<script>
    function cookieTest() {
        $.cookie("test", "Cookies are working!");
        alert($.cookie("test"));
    };
    cookieTest();
</script>

I checked a thousand times, and I don't see a reference typo. I tried this by viewing my site offline as well as online.

I downloaded the cookies plugin from .

Also, alerts work when I do this:

<script src="jquery.js"></script>
<script src="cookies.js"></script>
<script src="scripts/changeTheme.js"></script>
<script>
    function cookieTest() {
        alert("Test");
    };
    cookieTest();
</script>

My file is named cookies.js because I simply copied the source code from github and put it in a new js file. Directory

I can't figure out why I'm getting this simple error in the console:

Uncaught TypeError: $.cookie is not a function

Here is where I implement JavaScript and jQuery:

<script src="jquery.js"></script>
<script src="cookies.js"></script>
<script src="scripts/changeTheme.js"></script>
<script>
    function cookieTest() {
        $.cookie("test", "Cookies are working!");
        alert($.cookie("test"));
    };
    cookieTest();
</script>

I checked a thousand times, and I don't see a reference typo. I tried this by viewing my site offline as well as online.

I downloaded the cookies plugin from https://github./js-cookie/js-cookie.

Also, alerts work when I do this:

<script src="jquery.js"></script>
<script src="cookies.js"></script>
<script src="scripts/changeTheme.js"></script>
<script>
    function cookieTest() {
        alert("Test");
    };
    cookieTest();
</script>

My file is named cookies.js because I simply copied the source code from github and put it in a new js file. Directory

Share Improve this question edited Sep 11, 2016 at 17:17 asked Sep 11, 2016 at 17:04 user6819710user6819710 2
  • File name is js.cookie.js, check if it is a typo. – edonbajrami Commented Sep 11, 2016 at 17:05
  • You appear to be using syntax from an older version of cookie.js (from here: github./carhartl/jquery-cookie) whilst linking to a newer github repo with a version that isn't dependent on jQuery. – elmarko Commented Sep 11, 2016 at 17:17
Add a ment  | 

3 Answers 3

Reset to default 5

The library you're using is not a jquery plugin. Use an older version - https://github./carhartl/jquery-cookie/blob/master/src/jquery.cookie.js

As I didn't find any cdn source of this plugin I've copy-pasted it's content and it's working. Example: https://jsfiddle/wbcq3ho4/

<script src="CORRECT LIBRARY PATH HERE"></script>
<script>
    function cookieTest() {
        $.cookie("test", "Cookies are working!");
        alert($.cookie("test"));
    };
</script>

<button type="button" onclick="cookieTest();">
Click me
</button>

Just download the file manually or using bower/poser and put the correct link in your html code

This library is not based on jQuery, make sure you check out how to use it on GitHub.

It's

Cookies("yourCookie","yourCookieText");

本文标签: javascriptjQuery quotcookiequot not a functionStack Overflow