jQuery selector what's difference between jQuery(“element”) and $(“element”)?

后端 未结 2 1646
旧时难觅i
旧时难觅i 2021-01-24 11:00

I used jQuery many times ago, but always used like this: $(document). Lately i seen many times somebody using jQuery(document), I don\'t know differenc

2条回答
  •  时光取名叫无心
    2021-01-24 11:59

    @jAndy provides a good explanation about $ and jQuery in general.

    However for your specific problem, it seems that the plugin somehow makes $ unavailable, which either means that it overwrites $ with something else (unlikely) or that it calls jQuery.noConflict().

    If it does, have a look why it is doing this. Maybe it includes another library that needs $ for its own working.

    Usually, plugins should never assume that $ is available for them. @jAndy showed how to use $ if only jQuery is available.

    In addition if you put all your own code in the ready handler, the first argument passed is the global jQuery object, so you can name the parameter as you want:

    jQuery(function($) {
        // your code here
    }); 
    

提交回复
热议问题