+ 6

I really do not understand what 3 1 3 has to do with the document and how we arrived at it. Can someone help me understand that, please?

"3 1 3" ??? 😕

15th Jul 2016, 11:41 PM
Lawrence Ainetor
Lawrence Ainetor - avatar
5 odpowiedzi
+ 9
The script is looping through the document counting nodes. Each time it finds one it writes its type. In this case, it has found three: the first and third one is of type text (3) (it's white-space, but it's treated as text). The second one is of type 'element' (1).
17th Jul 2016, 3:37 AM
ZinC
ZinC - avatar
+ 2
OK thanks. This app is no longer explanatory enough. Cos it didn't even explain the node types and their values (like text = 3, and element = 1). And the document.body just contains <p>Some text</p> So where does the text come before the element and before another text again? I'm confused. Can you explain further please? I'll really appreciate it. Thanks.
17th Jul 2016, 11:02 AM
Lawrence Ainetor
Lawrence Ainetor - avatar
+ 2
OK yeah! I just realized that the numbers by the left that look like serial numbers (S/No.) are actually the values of the nodeTypes. I just don't know where and what (element, followed by texts/whitespace, followed by element) that produces {3 1 3} in <p>Some text</p>. Anyway, Thanks a lot. You've been so helpful.
19th Jul 2016, 10:17 PM
Lawrence Ainetor
Lawrence Ainetor - avatar
+ 1
Go back to that lesson and you"ll see a table listing all node types. As I wrote, and it's also mentioned in this app, white space is treated as text and thus considered a node.
19th Jul 2016, 9:55 PM
ZinC
ZinC - avatar
+ 1
ZinC, it would be great if we had the explanation step-by-step. Thanks a lot for your help and patience!
5th Aug 2016, 12:07 PM
Fabio Santos
Fabio Santos - avatar