Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

html child nodes count?

html child nodes count?

I'm trying to count the childnodes of textCalc. I count 7 child nodes but my browser counts 10. Can someone list the childnodes for me? I can't figure out what I'm not counting. lol.

<div id="taxCalc">

<input type="text" id="total" disabled><br />

<label>&nbsp;</label>

<input type="button" id="calculate" value ="Calculate" >

<input type="button" id="clear" value ="Clear">

</div>

3 Answers

Relevance
  • 6 years ago
    Favorite Answer

    I count 9. Four element nodes (input, label, input, input), plus 5 text nodes, each containing whitespace only. Maybe the browser has two text nodes after the first <input> and before <label>, one for each newline?

    Double-check your notes on text nodes. I'm fairly new to using DOM and don't know the exact rules for parsing multiple lines of text into text nodes in the document object. I suspect there is room for browser-dependence, since different browsers have traditionally handled spaces or newlines between tags differently.

  • Chris
    Lv 7
    6 years ago

    It depends on how much whitespace the source code contains.

    Here's the same HTML without whitespace, resulting in #children = #childNodes = 4: http://jsfiddle.net/khrismuc/k6cmhksd/

    Putting each element in a new line yields 9 childNodes, 5 textual ones wrapping 4 elements.

  • Anonymous
    6 years ago

    How did you get you 7 or 10... show us your code (use jsfiddle). I see only 4: input, label, input, input.

    Also, it's either taxCalc or textCalc (not both).

Still have questions? Get your answers by asking now.