Javascript firstChild在Edge中返回EmptyTextNode [英] Javascript firstChild returns EmptyTextNode in Edge
问题描述
我已经在浏览器(Opera,Chrome,FireFox)中进行了测试.firstChild函数可以正常运行,但是在Edge中它返回EmptyTextNode.
I've tested and in browsers(Opera, Chrome, FireFox) .firstChild function works correct, but in Edge it returns EmptyTextNode.
document.getElementById('breadcrumbsCategoryContainer').firstChild
该功能是否有Edge替代品?
Does there Edge has some alternatives, for this function?
推荐答案
这不是函数,而是属性.
It's not a function, it's a property.
听起来其他浏览器正在删除容器中第一个标签之前的空白,而IE Edge却没有.如果是这样,您可以使用firstElementChild
来获取第一个为 element 的孩子.请注意,对firstElementChild
的支持很好,但是某些较旧的浏览器没有此支持.
It sounds like the other browsers are removing whitespace prior to the first tag inside the container, and IE Edge isn't. If so, you can use firstElementChild
to get the first child that's an element. Note that support for firstElementChild
is good, but some older browsers don't have it.
或者,使用firstChild
和一个循环,跳过所有空白文本节点.
Alternately, use firstChild
and a loop, skipping past any blank text nodes.
这篇关于Javascript firstChild在Edge中返回EmptyTextNode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!