aw-bubakik
aw-bubakik

Reputation: 331

Javascript firstChild returns EmptyTextNode in Edge

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?

Upvotes: 2

Views: 908

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1075457

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.

Upvotes: 2

Related Questions