How to remove jQuery Conflict in prototype.js with 1.8.2.jquery.min.js

  • i am using 1.8.2.jquery.min.js for slideshow in home page. i have an error in console like this

    electronics.html (line 156) TypeError: element.attachEvent is not a function

    element.attachEvent("on" + actualEventName, responder); prototype.js (line 5653)

    TypeError: element.dispatchEvent is not a function

    element.dispatchEvent(event); prototype.js (line 5734)

    it makes menu drop-down in category page not working.

    I have tried jquery noConflict(); in all the way in Magento but it does not clear above bug. Also, I have tried some more methods from google to clear but it does work properly. can anyone help me to clear this error?

    show your codes. Where did you include your jquery file. How are you trying to avoid jquery conflict. Be specific

    First Load your 1.8.2.jquery.min.js and then prototype.js

    Check there may be more than one jquery files included.Remove all and replace by one.

  • In your local.xml:

    <reference name="head">
        <action method="addJs" name="jquery" as="jquery">
            <script>jquery-1.10.2.js</script>
        </action>
        <action method="addJs">
            <script>noconflict.js</script>
        </action>
    </reference>
    

    and noconflict.js would simply be

    $j = jQuery.noConflict();
    

    From there, anywhere you'd use $ for jQuery, you'd use $j instead.

    Alternatively, if its just for a slideshow, and I assume you have something similar to

    $(document).ready(function(){
        $('#target').slideshow();
    })
    

    you can do the following instead, and all the code within it would operate as normal:

    jQuery(document).ready(function($){
         $('#target').slideshow();
    });
    

    I personally prefer using `jQuery(...)`, you never know where your code will end up and it gets sloppy if some people use `$j`, while others use something different.

    @pspahn `$j` is the default in the new 1.9/1.14 rwd framework

    thanks but its not working still i have same error.

    @Karthick what did you try? Do you still need help?

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM