children [0]和firstElementChild之间有区别吗?

时间:2017-04-10 13:37:33

标签: javascript dom

ParentNode接口声明属性firstElementChild。我看到有人在任何地方使用children [0],所以我想知道,使用firstElementChildchildren[0]之间有区别吗?

1 个答案:

答案 0 :(得分:1)

children[0]将产生与firstElementChild相同的结果。 firstElementChild将第一个子节点作为元素节点返回(忽略文本和注释节点)。 IE6到IE8完全支持children属性。但是,在这些版本中,它返回元素节点和注释节点。 IE9 +只返回元素节点。

来源:W3C

继续摇摆!