Reputation: 803
Is it possible to change the name 'jQuery' in jquery's source code to something else.
I want to perform my jQuery operations with this new name.
eg:
jQuery('#something').attr();
to
myName('#something').attr();
How do I do this?
Upvotes: 0
Views: 872
Reputation: 6045
var $j = jQuery.noConflict();
// Use jQuery via $j(...)
$j(document).ready(function(){
$j("div").hide();
});
Upvotes: 1
Reputation: 318518
var myName = jQuery.noConflict(true);
This will restore both $
and jQuery
to whatever value (possibly undefined
) they had before and assign the jQuery object to myName
.
However, consider wrapping your code using jQuery in a closure where $
points to the jQuery object:
(function($) {
$('#something').something();
})(jQuery.noConflict(true));
People who work with your code expect $
to be used and will most likely be annoyed if they have to use something else; especially if it's something longer!
If you do not need to remove $
and jQuery
, do not use jQuery.noConflict(true)
but simply write jQuery
at the places where I used jQuery.noConflict(true)
.
Also remember that no jQuery plugins will work if you remove the global jQuery
before loading them (doing so after they are loaded is fine if they have been written properly, i.e. with the closure I suggested to you)
Upvotes: 7