Conflict between jquery.js

1

I am having a conflict between

<script src="assets/vendor/jquery/jquery-3.3.1.min.js"></script>

and the

<script src="//code.jquery.com/jquery-1.12.4.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

Does anyone know any way to solve? Both are existential

    
asked by anonymous 03.12.2018 / 09:09

1 answer

7

jQuery has the jQuery.noConflict function to work around conflict errors. It was originally meant to resolve conflicts with other libraries that also define the $ object, but can be used to use multiple versions of jQuery.

<script src="assets/vendor/jquery/jquery-3.3.1.min.js"></script>
<script>
    const $jQ3_3_1 = jQuery.noConflict();
</script>

<script src="//code.jquery.com/jquery-1.12.4.js"></script>
<script>
    const $jQ1_12_4 = jQuery.noConflict();
</script>

That is, as soon as you add jQuery 3.3.1 you use the noConflict function to create the instance in $jQ3_3_1 , as well as after you add jQuery 1.12.4 you use it again to create the $jQ1_12_4 , using every instance where you need it.

But this is probably unnecessary. Using jQuery in an application today is already questionable; to use two is even more so. It is not worth adding all the payload that the library only requires to use a feature . If it's a plugin you need, I recommend you look for something up-to-date and use just one of the versions in the application.

    
03.12.2018 / 11:44