What is the meaning of “$” sign in JavaScript

后端 未结 7 2159
无人共我
无人共我 2020-11-22 10:54

In the following JavaScript code there is a dollar ($) sign. What does it mean?

$(window).bind(\'load\', function() {
    $(\'img.protect\').pro         


        
7条回答
  •  情书的邮戳
    2020-11-22 11:38

    In addition to the above answers, $ has no special meaning in javascript,it is free to be used in object naming. In jQuery, it is simply used as an alias for the jQuery object and jQuery() function. However, you may encounter situations where you want to use it in conjunction with another JS library that also uses $, which would result a naming conflict. There is a method in JQuery just for this reason, jQuery.noConflict().

    Here is a sample from jQuery doc's:

    
    
    
    

    Alternatively, you can also use a like this

    (function ($) {
    // Code in which we know exactly what the meaning of $ is
    } (jQuery));
    

    Ref:https://api.jquery.com/jquery.noconflict/

提交回复
热议问题