美文网首页
NodeList和HTMLCollection类似数组

NodeList和HTMLCollection类似数组

作者: fb941c99409d | 来源:发表于2020-01-09 23:56 被阅读0次

详解参考
总结一下就是HTMLCollection是比较早期的模型,只能包含HTML元素,早期就有的接口如document.getElementsByClassName, document.getElementsByTagName返回的就是HTMLCollection。

NodeList是比较新的模型,相比HTMLCollection更加完善,不光有HTML元素,还有text节点和comment。
比较新的接口如document.querySelectorAll返回的就是NodeList。

NamedNodeMap 返回的是元素属性的集合
ul[0].attributes

NamedNodeMap {0: id, id: id, length: 1}
0: id
length: 1
id: id
__proto__: NamedNodeMap
getNamedItem: ƒ getNamedItem()
getNamedItemNS: ƒ getNamedItemNS()
item: ƒ item()
length: (...)
removeNamedItem: ƒ removeNamedItem()
removeNamedItemNS: ƒ removeNamedItemNS()
setNamedItem: ƒ setNamedItem()
setNamedItemNS: ƒ setNamedItemNS()
constructor: ƒ NamedNodeMap()
Symbol(Symbol.iterator): ƒ values()
Symbol(Symbol.toStringTag): "NamedNodeMap"
get length: ƒ length()
__proto__: Object

相关文章

网友评论

      本文标题:NodeList和HTMLCollection类似数组

      本文链接:https://www.haomeiwen.com/subject/shoeactx.html