How Do I Stop The Two Jquery Libraries From Conflicting With Each Other?
Solution 1:
you can safely use jQuery along with other libraries using .noConflict()
. usually, it's a conflict of the use of the $
function name.
i prefer doing jquery in the "closure" method:
(function($){
//i can use "$" safely in here
}(jQuery));
also, if you are using multiple versions of jQuery, then don't. just download the latest and use it. it should still cater some of the old API.
heres a sample code to show how this works:
//lets hijack the "$"
$ = (function() {
return {
libName: "some other library using $"
}
}());
//create a closure for us to use "$"
(function($) {
//we can now use the $ safely in this closure
$('body').text('hello world! in the body!');
//let's check "$" in hereconsole.log('in here, "$" is jQuery:',$);
}(jQuery));
//let's check "$" out hereconsole.log('out here, "$" is:', $);
Solution 2:
See jQuery's $.noConflict()
Although, you'd really be better off, reestablishing whatever plugin requires older jQuery and make use of new version only.
Solution 3:
Does $.noConflict()
works?
Import the js/jquery-1.5.2.min.js first and use $.noConflict()
to register js/jquery-1.5.2.min.js. Then use another code block and import another version of jQuery. In the end, rewrite the top banner using jQuery.xxx()
instead of $.xxx()
I think this should be work.
Solution 4:
Replace any one of them as specified:- Declare in any one of them
$a = jQuery.noConflict();
Replace all $ of that file by $a in that file
Solution 5:
the simple answer. add this at the end of your scripts.
<scriptsrc=""></script><scriptsrc=""></script><scripttype="text/javascript">
$.noConflict(true);
</script>
Post a Comment for "How Do I Stop The Two Jquery Libraries From Conflicting With Each Other?"