Is there any specific reason behind using $ with variable in jQuery

后端 未结 6 564
天涯浪人
天涯浪人 2020-11-27 16:10

I know it\'s a silly question but I am a bit confused with this. For example, if I have an input with an ID: rad1, is there any difference between below lines o

6条回答
  •  余生分开走
    2020-11-27 16:29

    It's only for showing that it's a Jquery variable.

    Declaring $a you're showing that your variable is for JQuery objects, it's just a notation. So the most readable thing will be to declare Jquery variable with $ notation

    var $obj=$("#obj");
    

    And DOM element without $ notation

    var obj = document.getElementById("obj");
    

提交回复
热议问题