开发者

jquery.cookie plugin, gettign an error saying jquery is not defined?

I included the jquery.cookie.js in my application and I am getting a firefox error saying jquery is not defined?

I have jquery in the project FOR SURE, removing the jquery.cookie.js 开发者_开发问答script gets rid of the error.

What could be the reason for this?


Make sure you have jQuery declared before jQuery.cookie.js

You can't use the jQuery object until it's declared and thus why it does matter the order.


if you are using mulitple versions of jquery in one script you might get that error. solution

Using different versions of jQuery and jQueryUI together


To make sure jQuery is available wrap your jQuery code in:

(function ($) {
     // your Code.
})(jQuery);

Additionally you may check for jquery.cookie:

(function ($) {
    if (typeof $.cookie != 'undefined'){
        var test = ($.cookie('test') === 'true');
    }
})(jQuery);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜