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
3 Answers
Reset to default 5The 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
版权声明:本文标题:javascript - jQuery "$.cookie" not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741866885a2401958.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论