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

后端 未结 2 1641
旧时难觅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:39

    $ is just a short reference to the global jQuery object.

    window.$ === window.jQuery // true
    

    Most plugin authors make sure that the dollar sign really is referencing the jQuery object, by putting it into a self-invoking method.

    (function( $ ) {
        // $(document)
    }( jQuery ));
    

    By invoking that anonymous method with the jQuery object as argument, we can access it within the method via $.

提交回复
热议问题