0
  1. Can we use different name as a selector in jQuery except $ and jQuery?

  2. If we are using two different frameworks which uses the same shortcut, one of them might stop working. At this moment we use noConflict() method. So is it a good practice to use it in only one framework (with jQuery) to solve above question?

Shivani
  • 153
  • 9
  • 2
    Does this answer your question? [Can I use multiple versions of jQuery on the same page?](https://stackoverflow.com/questions/1566595/can-i-use-multiple-versions-of-jquery-on-the-same-page) – Ajith May 13 '20 at 11:25
  • 1) yes 2) it's "good practice" to only use one framework. Not always an option I guess, but some don't work well together (not just due to reusing `$`) – freedomn-m May 13 '20 at 11:42

1 Answers1

1

One thing you can do is assign jQuery to a different variable:

var foo = jQuery.noConflict();

foo(".myclass#mydiv").toggle();

Reference: https://api.jquery.com/jquery.noconflict/

If you are using 2 different jQuery versions on the same page,


var new$ = jQuery.noConflict(true);

// Usage
new$(".foo#bar[type=baz]").hide();

// Version Matching
console.log($.fn.jquery) // Other version
console.log(new$.fn.jquery) // Version defined above
RealZombs
  • 135
  • 1
  • 12