admin管理员组

文章数量:1390803

To resolve a conflict between jQuery and prototype,
is there any way other than asking jQuery to resolve via

jQuery.noConflict

and using jQuery instead of $('code').code;

Can't we ask prototype $ to step down and resolve.

To resolve a conflict between jQuery and prototype,
is there any way other than asking jQuery to resolve via

jQuery.noConflict

and using jQuery instead of $('code').code;

Can't we ask prototype $ to step down and resolve.

Share Improve this question edited Nov 21, 2017 at 5:01 Gaurav Mishr asked Feb 3, 2010 at 5:38 Gaurav MishrGaurav Mishr 5706 silver badges21 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

You should namespace your code anyway, and jQuery gives you a good opportunity to re-claim the $ in the same step:

jQuery.noConflict();

jQuery(function ($) {
    // $ is the jQuery object in here
    // and doesn't conflict with Prototype
});

As described here.

I don't know if you can make Prototype "step down", but this is a perfectly elegant and working solution.

PrototypeJS adds a bit more to the global JavaScript namespace than jQuery does. For example, it adds meanings for: Ajax, $, $$, $F, Abstract, Form, $A, $H, $R, $w. You can look at a plete list of classes and utilities at api.prototypejs.

So the advice you've gotten is correct, There's no simple equivalent to jQuery.noConflict() for PrototypeJS.

I can't find any function in http://api.prototypejs/ that will give back the $, like noConflict() in jQuery.

I wonder, what feature that you need so you still using prototype? jQuery might have plugins for that feature. Using 2 libraries in same page will make your page bloated by the size of each library.

本文标签: javascriptHow can we resolve conflict between prototype and jQueryStack Overflow