Why does `childNodes` return a number larger than I expect?

前端 未结 6 2152
有刺的猬
有刺的猬 2020-12-01 17:02

Could you please look at this jsFiddle example, and tell me why the number \'11\' is alerted rather than \'5\' (the number of

  • elements)?

    From

  • 6条回答
    •  情话喂你
      2020-12-01 17:25

      As others have pointed out, the childNode count inclues the text nodes, generated by the whitespace between the

    • elements.

      • milk
      • butter
      • eggs
      • orange juice
      • bananas

      That will give you 5 childNodes because it omits the whitespace.

    提交回复
    热议问题