# Js选择器
JS选择器常用的有`getElementById()`、`getElementsByClassName()`、`getElementsByName()`、`getElementsByTagName()`、`querySelector()`、`querySelectorAll()`。
## getElementById
通过`id`来定位,返回对指定`id`的第一个对象的引用,返回类型为`HTMLDivElement`。
```html
T1
```
## getElementsByClassName
通过`class`属性来定位,返回文档中指定`class`属性值的元素的引用,返回类型为`HTMLCollection`。
```html
D2
D3
```
## getElementsByName
通过`name`属性来定位,返回文档中指定`name`属性值的元素的引用,返回类型为`NodeList`。
```html
D4
D5
```
## getElementsByTagName
通过标签的名字来定位,返回文档中指定标签的元素的引用,返回类型为`HTMLCollection`。
```html
P6
P7
```
## querySelector
通过`CSS`选择器来定位,返回文档中匹配指定`CSS`选择器的第一个元素的引用,返回类型为`HTMLDivElement`。
```html
```
## querySelectorAll
通过`CSS`选择器来定位,返回文档中匹配指定`CSS`选择器的所有元素的引用,返回类型为`NodeList`。
```html
```
## 代码示例
```html
Js选择器
D1
D2
D3
D4
D5
P6
P7
```
## 每日一题
```
https://github.com/WindrunnerMax/EveryDay
```
## 参考
```
数组的遍历 https://github.com/WindrunnerMax/EveryDay/blob/master/JavaScript/Js%E9%81%8D%E5%8E%86%E6%95%B0%E7%BB%84%E6%80%BB%E7%BB%93.md
ES6箭头函数 https://github.com/WindrunnerMax/EveryDay/blob/master/JavaScript/ES6%E6%96%B0%E7%89%B9%E6%80%A7.md
原型与原型链 https://github.com/WindrunnerMax/EveryDay/blob/master/JavaScript/%E5%8E%9F%E5%9E%8B%E4%B8%8E%E5%8E%9F%E5%9E%8B%E9%93%BE.md
CSS选择器 https://github.com/WindrunnerMax/EveryDay/blob/master/CSS/CSS%E9%80%89%E6%8B%A9%E5%99%A8.md
```