Several of my pages use both JQuery and Protoype. Since I upgraded to version 1.3 of JQuery this appears to be causing problems, because both libraries define a function nam
Currently you can do something like this:
<head>
<script type="text/javascript" src="/obp/js/prototype.js"></script>
<script type="text/javascript" src="/obp/js/jquery.js"></script>
<script type="text/javascript">
var $j = jQuery.noConflict();
</script>
</head>
Then, use jQuery as $j()
and Prototype's $()
.
You need to load it in your public/javascript/application.js
jQuery.noConflict();
var $j = jQuery;
This is also a good article that may be helpful.
JQuery & Prototype working together
It would seem that the most simple answer would be to bite the bullet, and include your noConflict lines. Of course if your pages aren't using a shared header, that solution might not be the best.
You could call jquery first and then set
var $j = jQuery;
prototype will take control of $
in this case.
Or, you could just refer to jQuery by using the full jQuery function name (jQuery).
Use Prototype below jQuery like this:
<script type="text/javascript" src="news/jquery-1.2.3.pack.js"></script>
<script type="text/javascript" src="news/jquery.easynews.js"></script>
<script type="text/javascript" src="lb/js/prototype.js"></script>
<script type="text/javascript" src="lb/js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="lb/js/lightbox.js"></script>
<link href="lb/css/lightbox.css" rel="stylesheet" type="text/css" />
in this case the jQuery function will create a problem, so you can use this to solve the problem:
<script type="text/javascript">
jQuery.noConflict();
var JQ = jQuery;//rename $ function
</script>
This solution worked fine:
jQuery.noConflict();
var $j = jQuery;
Now use $j
in place of $
for your jQuery code, like:
$j(document).ready(function() {
$j('#div_id').innerfade({
// some stuff
});
});