Yahoo Clever wird am 4. Mai 2021 (Eastern Time, Zeitzone US-Ostküste) eingestellt. Ab dem 20. April 2021 (Eastern Time) ist die Website von Yahoo Clever nur noch im reinen Lesemodus verfügbar. Andere Yahoo Produkte oder Dienste oder Ihr Yahoo Account sind von diesen Änderungen nicht betroffen. Auf dieser Hilfeseite finden Sie weitere Informationen zur Einstellung von Yahoo Clever und dazu, wie Sie Ihre Daten herunterladen.
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> </label>
<input type="button" id="calculate" value ="Calculate" >
<input type="button" id="clear" value ="Clear">
</div>
3 Antworten
- husoskiLv 7vor 6 JahrenBeste Antwort
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.
- ChrisLv 7vor 6 Jahren
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.
- Anonymvor 6 Jahren
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).