How do I change the $ function in jquery for another word for make it compatible with other framworks
views:
98answers:
6
+2
A:
It's only an alias for jQuery - if $ causes you problems, use jQuery
instead.
David M
2009-07-17 15:22:40
Tnks very helpfull
2009-07-17 15:25:18
+4
A:
This will un-assign the $ variable
jQuery.noConflict();
But even more useful is being able to reassign the jQuery object to another terse variable, such as
var $j = jQuery.noConflict();
Of course you can make $j anything you want.
Jon Erickson
2009-07-17 15:24:00
A:
You can use the noConflict() method like so:
var myjquery = jQuery.noConflict(true);
myjquery(document).ready( function() {
// The usual...
} );
Plutor
2009-07-17 15:24:15
A:
use jQuery.noConflict();
if you still want to use the $
shorthand in your jQuery code then you can use a self-invoking anonymous function to do so
(function($) {
// $ is shorthand for jQuery inside this function :)
})(jQuery);
Russ Cam
2009-07-17 15:24:49
A:
or you can use closure, this way:
jQuery(document).ready(function($){
$('div') //use regular $
})
However... WHY? Why do you want to load more than once library?
Ionut Staicu
2009-07-17 15:25:09
Ok, the thing is that Im using a jquery acordion, it cames with the jquery and the plug in, and every thing its writen with jquery insted of $, but a try to upgrade to a newer version of jquery, but the accordion stop working.
2009-07-17 15:30:33
well... the problem may be with the accordion. However, if is a simple accordion, you may try this way: http://dev.iamntz.com/166/jquery-accordion-tutorial :)
Ionut Staicu
2009-07-17 19:58:07