10

Is there any way to use both the jquery and scriptaculous js files together?

I was trying to implement the autocomplete feature of the cakephp framework which required the js files,prototype.js,scriptaculous.js,effects.js and controls.js.

I also use JQuery functions in my application which requires the jquery.js file.

The auto complete feature does not work if I include the jquery.js file. But I also require the jquery.js files to implement my jquery functions.

So is there any method to use both the js files?

Rob W
  • 341,306
  • 83
  • 791
  • 678
Angeline
  • 2,369
  • 22
  • 68
  • 107
  • 3
    Did you see this link?: http://docs.jquery.com/Using_jQuery_with_Other_Libraries – Zed Aug 04 '09 at 11:09

2 Answers2

22

You would need to enable no-conflict mode in jQuery, see:

http://docs.jquery.com/Using_jQuery_with_Other_Libraries

From the above link:

<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>

However, you will still need to load Prototype for Scriptaculous to work. As a suggestion, you may want to try out jQuery's autocomplete plugin, if you're using those other libraries just (or mainly) for an autocompleter widget.

karim79
  • 339,989
  • 67
  • 413
  • 406
1

The easiest way to do both jQuery and Scriptaculous is to do:

var $j = jQuery.noConflict();

and use $j instead of $ for jQuery.

$j('#id'), for example.

Code Lღver
  • 15,573
  • 16
  • 56
  • 75