Known jQuery/Prototype conflict - problems solving it, though

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • luftikus143
    New Member
    • Jan 2007
    • 97

    Known jQuery/Prototype conflict - problems solving it, though

    I am using prototype and jquery, and as noted on many sites, there is some potential for conflicts. Now, I saw as well again and again this solution:
    Code:
     <html>
     <head>
       <script src="prototype.js"></script>
       <script src="jquery.js"></script>
       <script>
         var $j = jQuery.noConflict();
         
         // Use jQuery via $j(...)
         $j(document).ready(function(){
           $j("div").hide();
         });
         
         // Use Prototype with $(...), etc.
         $('someid').hide();
       </script>
     </head>
     <body></body>
     </html>
    Now, I have another, quite long javascript file which is being included and references jquery. There are lots of "$" refrences, such as "function($ )", "$this.css" , "$(_tagMain).da ta"...

    Do I need to replace then all of the "$" with "$j"? Or could it be that I will then badly reference some of these calls/methods?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    If I see it right, Prototype uses $, thus (and because jQuery is set to $j) anything you call using $ will try to execute the Prototype Framework.

    if you want to use jQuery, you have to use $j.

    Comment

    • luftikus143
      New Member
      • Jan 2007
      • 97

      #3
      if you want to use jQuery, you have to use $j.
      Yes, that's something I understood. The question is more, if I need to replace each and every occurrence of "$" with "$j" in the JS file which uses jQuery?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        The question is more, if I need to replace each and every occurrence of "$" with "$j" in the JS file which uses jQuery?
        that’s what the sentence implies. $ → Prototype, $j → jQuery. thus if you want to use jQuery (be it existing code or not) you have to use, resp. rewrite it to $j.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          I know this doesn't directly answer the question, but it's an important point nonetheless. Is there any reason why you need to use both prototype and jQuery? You should never really need to use more than one library/framework.

          Comment

          • luftikus143
            New Member
            • Jan 2007
            • 97

            #6
            Originally posted by acoder
            I know this doesn't directly answer the question, but it's an important point nonetheless. Is there any reason why you need to use both prototype and jQuery? You should never really need to use more than one library/framework.
            Yes, I thought about that question too. But unfortunately, it seems that yes, as I have on lib using scriptaculous, and another one using jQuery.

            Comment

            Working...