Javascript firstChild returns EmptyTextNode in Edge

 ̄綄美尐妖づ 提交于 2019-12-11 11:12:53

问题


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:


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.



来源:https://stackoverflow.com/questions/34176308/javascript-firstchild-returns-emptytextnode-in-edge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!