1

I have a conflict between jQuery and another library. I added the code below to the local.xml file as per answers found here.

<?xml version="1.0"?>
<layout>
 <default>
 <reference name="head">
 <action method="addJs" name="jquery" as="jquery">
 <script>jquery-1.11.1.js</script>
 </action>
 <action method="addJs">
 <script>noconflict.js</script>
 </action>
</reference>
</default>
</layout>

The answer said that the noconflict.js file should simply contain the following code.

$j = jQuery.noConflict();

I do not understand where I have to add the noconflict.js file. Is it to the js folder on the server? If the answer is yes, how do I create a JavaScript file?

asked Jan 12, 2016 at 6:08

3 Answers 3

4

You can always bypass the noConflict() method by wrapping your jQuery in an IIFE: http://benalman.com/news/2010/11/immediately-invoked-function-expression/.

(function($){
 //use your jQuery code here
})(jQuery);

OR just use jQuery instead of $.

answered Jun 18, 2016 at 7:54
0

Include the jquery.noConflict in the app/design/frontend/default/[theme name]/template/page/html/head.phtml file like this:

<script type="text/javascript">
 $.noConflict(); //Use no conflict here instead of js file
 // Code that uses other library's $ can follow here.
</script>

See details via following link: http://api.jquery.com/jQuery.noConflict/

answered Jan 12, 2016 at 6:44
3
  • in the header.phtml right? Commented Jan 12, 2016 at 7:02
  • @shamz head.phtml, not header.phtml Commented Jan 12, 2016 at 7:12
  • i did the same but doesnt seem to work though.... Commented Jan 12, 2016 at 7:24
0

In the file jquery-1.11.1.js, add jQuery.noConflict(); at last.

answered May 16, 2016 at 4:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.