1

Please help!!! I am trying to set this cookie but it is not working. I get an error message that says "Uncaught TypeError: cannot call method 'cookie' of undefined". I dont know why it is saying this. I had this before i added a path and domain so i know that is not what is causing the problem.

my code is

<script src="jquery-2.0.3.js"></script>
<script src="jquery-cookie/jquery.cookie.js"></script>
<script type="text/javascript">
$.noConflict();
//<![CDATA[

var word = "hello";


var cook = $.cookie("newAr", "word", {expires: 3, path: '/', domain: 'http://localhost/test.html'});

$.cookie("newAr");
document.write("step 1");

//]]>
</script>
user1516734
  • 11
  • 1
  • 4

2 Answers2

0

You cannot use $ to access jquery methods after you have said this

$.noConflict();

Remove this statement. It means there is someone else(library) other than jquery using the $` symbol and I see in your case there is nothing like that.

mohkhan
  • 11,925
  • 2
  • 24
  • 27
0

the best way to perform the jQuery code without conflict is

(function($){
    var word = "hello";
    var cook = $.cookie("newAr", "word", {expires: 3, path: '/', domain: 'http://localhost/test.html'});
    $.cookie("newAr");
    document.write("step 1");
})(jQuery);
Rohit Agrawal
  • 5,372
  • 5
  • 19
  • 30