Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialkaran Badhwar
Web Development Techdegree Graduate 18,135 PointsWhite space and text nodes
<label> ''Confirmed'' <input type = 'checkbox'.......> </label>
So when we do label.firstChild will that be the Text or the White space.
I am really confused about the whole white spacing thing with text nodes.
2 Answers
Steven Parker
231,275 PointsThis node has 3 children. The first child is a text node containing ''Confirmed''
(white space included), the next one is the input element, and the last one is another text node with just the space between the input and the closing tag.
karan Badhwar
Web Development Techdegree Graduate 18,135 PointsSo you mean to say this example will have 3 white spaces encountered Text Nodes, 1st one with text (Confirmed)
<label>
'Confirmed'
<input.....>
<p>For Example</p>
</label>
am I right?
Steven Parker
231,275 PointsYes, 5 child nodes total, 3 of them are text nodes.
karan Badhwar
Web Development Techdegree Graduate 18,135 Pointskaran Badhwar
Web Development Techdegree Graduate 18,135 PointsHi Steven, Thankyou for your explanation. But how it measures white space for ex as you said space between input and the closing tag, but how about the space between the 'confirmed' and the opening tag, why is that space included into the text Node?
Steven Parker
231,275 PointsSteven Parker
231,275 PointsA space is just a text character, it is not handled specially. So if there is space between elements, or a word, or words and spaces, in all cases you still only get one text node that contains it all.