views:

86

answers:

5

Hello,

I am using prototype + jquery on a site. Now the prototype plugins use $. I do not want jQuery to use $. How do I make jQuery not register the $. Also, how do I then call jQuery functions.

Thank you for your time.

+15  A: 

The jQuery documentation has an article on how to make jQuery play nice with other libraries.

This is one suggested way from that article:

<html>
<head>
  <script src="prototype.js"></script>
  <script src="jquery.js"></script>
  <script>
    jQuery.noConflict();

    // Put all your code in your document ready area
    jQuery(document).ready(function($){
      // Do jQuery stuff using $
      $("div").hide();
    });

    // Use Prototype with $(...), etc.
    $('someid').hide();
  </script>
</head>
<body></body>
</html>
Marquis Wang
+3  A: 
  1. link jquery first and prototype second. this will override the $.
  2. for jQuery, use the function jQuery(...).
Kobi
I find that this is the best method for when you want to use jQuery throughout the page (situations such as onclick attributes).
Josiah
+1  A: 

You can use jQuery.noConflict( ); And then you can remap it like this: $j = jQuery;

Artem Barger
or: var $j = jQuery.noConflict();
nickf
A: 

You can use jquery's noConflict method:

var jQ=jQuery.noConflict();

now onwards you can use jQ in place of "$" to work with jQuery functions and use $ for prototype.

TheVillageIdiot
+1  A: 

this is what I use if it's only a small bit of jQuery

jQuery(function($) {

    // now you can use $ again within here - this block of code is fired on DOM ready

});
alex