开发者

How to create a global shortcut while using JQuery noconflict

开发者 https://www.devze.com 2023-03-31 17:57 出处:网络
How to declare a global window object while using jQuery.noConflict(). I am using following way to avoid Jquery conflict with Mootools

How to declare a global window object while using jQuery.noConflict().

I am using following way to avoid Jquery conflict with Mootools

 var $j = jQuery.noConflict();

Now I would like to create global shortcut in jquery and tried as

 window.cc = function() {// code}

But fails and return er开发者_StackOverflow社区ror as cc not deined.


Instead of creating explicit no conflict object we can use jQuery in place of $ or your no conflict object name.


Closures?

jQuery.noConflict();

(function($){
    //code goes here
    // here $ is now jQuery
})(jQuery);

// here $ is not jQuery

and in any of these you can use $ to refer to the jQuery object.

note: I'd also make sure jQuery loads up after any other framework for .noConflict() to work.

0

精彩评论

暂无评论...
验证码 换一张
取 消