arnexmx
arnexmx

Reputation: 16

Conflicts in using both jQuery and prototype

Is it possible to use both jQuery and prototype scripts without having any collisions or overwritten variables? I don't know if since I last used prototype a few months back this has been fixed.

Upvotes: 0

Views: 305

Answers (2)

seoul
seoul

Reputation: 864

$ is used by both and I believe this is the source of conflict.

Since your previous code is in prototype so it is better to keep it as it is, you just make sure no jQuery code face conflict with prototype by $.

For this, wrap your code in a function and pass jQuery object to that function. Do as I describe below:

If your code is:

/* begin  */

// your variables
// your functions which $ goes here
// other stuff

/* end */

Then, transform this as follows:

(function($) {

  /* begin  */

  // your variables
  // your functions which uses $ is safe now; inside this code block.
  // other stuff

  /* end */

})(jQuery); // passing jQuery removes conflict, ta-da :-)

Upvotes: 2

Matt Ball
Matt Ball

Reputation: 359786

Is it possible to use both jQuery and prototype scripts without having any collisions or overwritten variables?

Of course. Just use jQuery.noConflict().

Upvotes: 2

Related Questions