MyBB Community Forums

Full Version: JQuery & Prototype Conflict in Mybb
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

In Mybb when you use Jquery, conflict issue arises e.g: Rich textbox, collapse and expand options in different listing pages stops working.

After facing a problem and finding a solution of jQuery and prototype conflict I am sharing the solution with you all.

By default, jQuery uses "$" as a shortcut for "jQuery". However, you can override that default by calling jQuery.noConflict() at any point after jQuery and the other library have both loaded. For example:

 <html>
 <head>
   <script src="prototype.js"></script>
   <script src="jquery.js"></script>
   <script>
     jQuery.noConflict();
     
     // Use jQuery via jQuery(...)
     jQuery(document).ready(function(){
       jQuery("div").hide();
     });
     
     // Use Prototype with $(...), etc.
     $('someid').hide();
   </script>
 </head>
 <body></body>
 </html>

This will revert $ back to its original library. You'll still be able to use "jQuery" in the rest of your application.

If you are using any jQuery library that uses "$" as a shortcut for "jQuery" then you need to replace all "$" with "jQuery". This will solve your problem.

I hope this thread will be helpful for you Smile.

Thanks




Another "tutorial" on this matter? Really?

Anyway, I'd advise anybody following this guide that they should pass $ as a parameter to the function as there are a few cases where using jQuery just doesn't work - using AJAX being an example I've found in the past.

I suggest using the following instead:

jQuery.noConflict();

jQuery(document).ready(function($)
{
    $('.someClass').hide(); // or whatever you want to do.
});
(2012-03-16, 11:43 AM)euantor Wrote: [ -> ]Another "tutorial" on this matter? Really?

I agree. This has been known/posted in the community a billion times.
It popped up on Google before the others so I'm thankful.
Finally. A solution to this madness. Toungue
(Sorry for Necroposting. Just realized how old this was.)
(2012-03-16, 11:43 AM)Euan T Wrote: [ -> ]Another "tutorial" on this matter? Really?

Anyway, I'd advise anybody following this guide that they should pass $ as a parameter to the function as there are a few cases where using jQuery just doesn't work - using AJAX being an example I've found in the past.

I suggest using the following instead:

jQuery.noConflict();

jQuery(document).ready(function($)
{
    $('.someClass').hide(); // or whatever you want to do.
});

Guess it does get annoying to a lot of people, Carn't wait till the new release of mybb it will be using jquery.