JQuery does not conflict

For the most part .noConflict () works fine for me, for example:

$jq('#no-thanks').click( function(event) {
    $jq("#olsu").fadeOut();             
});

but what is the syntax for:

$.cookie("example", "foo", { expires: 7 });

I tried:

$jq.cookie("example", "foo", { expires: 7 })

and

$jq().cookie("example", "foo", { expires: 7 })

any ideas?

+5
source share
5 answers

This should work:

(function($){
  // your all jQuery code inside here

  $.cookie("example", "foo", { expires: 7 });

})(jQuery);

Now you can use $it without fear of conflict with other libraries if you put your jQuery code in a self-named anonymous function.

Read more Explanation here

+8
source

Have you added a jquery.cookie.jsscript to your page?

jQuery.cookieis not a built-in jQuery function, so you need to make sure that it is added and that it is correctly added to jQuery if it was called after noConflict.

jQuery, jQuery $ . , document.ready jQuery - $:

(function ($) {
  //code goes here
}(jQuery));

jQuery(function ($) {
  //document.ready code goes here
});
+2

What about

jQuery.cookie("example", "foo", { expires: 7 })

You can also just get rid of your life by wrapping your code with an anonymous function and passing it jQuery:

(function($){
  $('#no-thanks').click( function(event) {
    $("#olsu").fadeOut();             
    $.cookie("example", "foo", { expires: 7 });

  });
})(jQuery)
0
source

Have you tried calling jQuery directly?

jQuery.cookie("example", "foo", { expires: 7 })
0
source

I'm not sure where you got it $jq, but a jQuery object jQuery, so:

jQuery.cookie("example", "foo", {expires: 7});
0
source

All Articles