Put JS only in a div

Asked

Viewed 47 times

0

My question is this, I have a div I need her to have a less up-to-date version of js.

My page has the Bootstrap 4.1 and need to rotate the jquery 2.2.3 in the div, where the most updated version (3.2.1) causes the content to blink and is not displayed correctly.

  • Vc is actually using jquery-3.2.1.slim. js version ?

1 answer

5


Yes you can use several versions on the same page. jquery allows this by using a function called noConflict. In your case it would look like this to load the scripts on the page:

 <script src="jquery/3.2.1/jquery.js" type="text/javascript"></script>
 <script src="jquery/2.2.3/jquery.js" type="text/javascript"></script>
 <script>var $j = jQuery.noConflict(true);</script>

When using $() will be using version 3.2.1 when using $j() will be using version 2.2.3.

So, anything related to that particular div, use $j, which can be renamed to something else you prefer, like $j223 for example, and correctly place the filenames in the tag script.

Here the documentation: jquery.noconflict

  • Then the script statement 2.2.3, I put inside the div?

  • If you have script inside the div you can declare inside, and the scripts related to the div need to be changed... for example if in the div you had an id "Divx", you would need to change to $j('#divX')

  • It worked right here, thank you very much!

Browser other questions tagged

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