How to obtain a node on the location NodeList

1. Array similar wording in the brackets: 

document.body.childNodes[0]

2. Use NodeList.prototype.item (): 

document.body.childNodes.item(0);

 

Note: [] and item () when the write parameters are not given, when the parameter is greater than or equal to length, [] will return undefined manner, item () returns null mode

 

Suggested Use: [] 

Guess you like

Origin www.cnblogs.com/aisowe/p/11511951.html