开发者

What is the difference between "jQuery(selector)" and "$(selector)"? [duplicate]

开发者 https://www.devze.com 2023-03-16 05:05 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: What is the difference between $ and jQuery
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

What is the difference between $ and jQuery

I've noticed cases where "jQuery(selector)" is used instead of "$(selector)", what is the d开发者_JAVA百科ifference between both of any?


None. Normally, the $ variable simply points to jQuery. You might be using jQuery instead in cases where the $ is used by another library, or you are using it for other purposes in your code.


None. $ is merely an alias to jQuery. However, when developing code for public consumption, you should use jQuery instead of $, as $ might be assigned to something else, if they use more than one framework. Or just use a closure to make $ a private variable, which is what most plugins do:

(function($){
    // Use $ normally here...
})(jQuery);


Its just an alias for the same thing - to avoid conflicts in something like Wordpress, or frameworks that might import their own version of jQuery.


jQuery is used when you have another javascript library that uses the $ variable. jQuery===$

0

精彩评论

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