Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript DOM Scripting By Example Improving the Application Code Next Steps

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree
karan Badhwar
Web Development Techdegree Student 13,000 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
216,175 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
karan Badhwar
Web Development Techdegree Student 13,000 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
216,175 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
karan Badhwar
Web Development Techdegree Student 13,000 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
216,175 Points

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