Conflict between jquery.js

Asked

Viewed 216 times

1

I’m conflicted between the

<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 resolve? both are existential

  • Out of curiosity, why you need different versions?

  • the latest controls the graphs, tables... basically the project structure and the older ones control my autocomplete input.

  • Wouldn’t it be the case to create an autocomplete component with a more updated version and thus keep your libraries always up to date? It is more feasible to change all tables, charts, etc.

1 answer

7

jQuery has the function jQuery.noConflict to circumvent conflict errors. It was originally made 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 function noConflict to create the $jQ3_3_1, as well as after you add jQuery 1.12.4 you use again to create the instance $jQ1_12_4, using every instance you need.

But this is probably unnecessary. Using jQuery in an application today is questionable; using two is even more so. Not worth adding all the payload that the library requires only to use a Feature. If it’s a plugin that you need, I recommend that you look for something updated and use only one of the versions in the application.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.