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 jQuery Basics (2014) Creating a Password Confirmation Form Perform: Part 1

Justin Sze Wei Teo
Justin Sze Wei Teo
9,418 Points

$("form span") selector okay without mentioning intermediary 'p' element?


For the selector used , i.e. "form span" , why is it that 'p' is not mentioned and this works? Isn't the span a child of the paragraph <p> element, which is then in turn the child of the form?

Does this imply it is ok to skip a few childs to point at which element we're selecting?

Kindly advise, thanks!

1 Answer

Benjamin Barslev Nielsen
Benjamin Barslev Nielsen
18,958 Points

Yes, "form span", just means the span needs to be inside a form tag, the form does not need to be the parent of the span. However, if you use the selector:

form > span

span needs to be a child of a form element.