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 trial

JavaScript DOM Scripting By Example Improving the Application Code Next Steps

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

White 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
Steven Parker
231,236 Points

This 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
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

Hi 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
Steven Parker
231,236 Points

A 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.

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

So 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
Steven Parker
231,236 Points

Yes, 5 child nodes total, 3 of them are text nodes.