开发者

Conflicts between jQuery and Prototype

I am building a rails application and installing this gem called "best-in-place" for one-time editing. It was working for a while, but after I struggled with jQuery and Prototype conflicts, it stopped working and now I get this error message when trying to load the page.

error http://dl.getdropbox.com/u/3481269/Screen%20shot%202011-04-30%20at%206.17.45%20PM.png

I am including both the jQuery and prototype JS files.

    <script src="/javascripts/jquery.js?1303396383" type="text/javascript"></script> 
<script src="/javascripts/rails.js?1303562965" type="text/javascript"></script> 
<script src="/javascripts/application.js?1303842064" type="text/javascript"></scri开发者_运维问答pt> 

    <script language="javascript" type="text/javascript"> 
        $j = jQuery.noConflict();
    </script> 

    <script src="/javascripts/prototype.js?1303686720" type="text/javascript"></script> 
<script src="/javascripts/jquery.purr.js?1302145859" type="text/javascript"></script> 
<script src="/javascripts/best_in_place.js?1302150372" type="text/javascript"></script> 

Can you help me trouble-shoot what might be the cause for this error?


You are assigning the jQuery .noConflict() method to $j so for jQuery stuff you must now use $j not $ so for instance $j(document).ready(...


I'm assuming that the best-in-place plugin is for jQuery, so forgive the rest of this if I'm mistaken. Unless you have written a ton of JS that depends on Prototype in your app, I'd probably ditch it in favor of jQuery. It's pretty easy to make the switch.

Even though it's possible to use both with proper namespacing, it's not worth it. There's a massive amount of overlap between the two, and you're adding a lot of extra weight to your code. One JavaScript framework should be enough for one page! :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜