firstChild issues in HTML

Getting unexpected results from calling firstChild

The firstChild method might not work as you expect. For example, in the below block if you select the div and try to get its firstChild, you might be surprised to see that it is the newline and the indentation instead of the span element.

However, if you tried to use firstElementChild instead you would get the span as expected.

<div>
  <span>Text</span>
</div>

Join Sudhansu Bhushan on Peerlist!

Join amazing folks like Sudhansu Bhushan and thousands of other builders on Peerlist.

peerlist.io/

It’s available... this username is available! 😃

Claim your username before it's too late!

This username is already taken, you’re a little late.😐

0

1

0