简体   繁体   English

RightJS:getElementById vs $('element_id')

[英]RightJS: getElementById vs $('element_id')

I am learning javascript and using RightJS. 我正在学习javascript并使用RightJS。 What is the difference between the following? 以下有什么区别?

var thing = $('thing1')

and

var thing = document.getElementById('thing1')

Type it into the browser's console 将其输入浏览器的控制台

> $("head")
  by {_: div#head, constructor: function, initialize: function, parent: function, parents: function…}
> document.getElementById("head");
  <div id=​"head">​…​</div>​

You can see the $ returns some sort of wrapped object and that getElementById returns an Html Node. 你可以看到$返回某种包装对象,getElementById返回一个Html节点。

Check out their docs on Util.$ 查看他们关于Util。$的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM