Javascript firstChild returns EmptyTextNode in Edg

2019-08-11 14:07发布

I've tested and in browsers(Opera, Chrome, FireFox) .firstChild function works correct, but in Edge it returns EmptyTextNode.

document.getElementById('breadcrumbsCategoryContainer').firstChild

Does there Edge has some alternatives, for this function?

1条回答
该账号已被封号
2楼-- · 2019-08-11 14:48

It's not a function, it's a property.

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.

Alternately, use firstChild and a loop, skipping past any blank text nodes.

查看更多
登录 后发表回答