The $ dollar sign

后端 未结 9 1821
执笔经年
执笔经年 2020-11-29 04:16

I have something simple like this:

$(selector).append("somestuff");

But since I\'m going to reuse the selector I cache it with:

9条回答
  •  猫巷女王i
    2020-11-29 04:40

    RichieHindle is correct. To expand:

    Javascript variables allow the '$' character. So for example, you could have the following:

    var $i = 1;
    var i = 1;
    

    Both i and $i have the same value, and both are perfectly legitimate variable names.

    jQuery assigns itself (the jQuery object) to '$' because traditionally, that's what Javascript frameworks have done for selectors. There's no inherent meaning to '$' beyond what jQuery gives it.

提交回复
热议问题