confusion over simple variable declaration jQuery “$variable” vs javascript “var”

后端 未结 5 1967
被撕碎了的回忆
被撕碎了的回忆 2020-12-04 15:48

I have this simple ghost text implementation:

HTML code:

5条回答
  •  星月不相逢
    2020-12-04 16:33

    When storing a jQuery selection in a variable, it's common practice to add a $ before the variable name like this:

    var $banner = $('#banner');
    

    It's not necessary to include the dollar sign — var banner = $('#banner') would work just as well. However, the dollar sign reminds you that the variable holds a jQuery selection and not just any value like a number or a string.

提交回复
热议问题