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

Why do you have to use "form span" and not "p span"?

I wanted to try and perform the code this way: ''' $("p span").hide(); ''' ''' <form action="#" method="post"> <p> <label for="username">Username</label> <input id="username" name="username" type="text"> </p> <p> <label for="password">Password</label> <input id="password" name="password" type="password"> <span>Enter a password longer than 8 characters</span> </p> <p> <label for="confirm_password">Confirm Password</label> <input id="confirm_password" name="confirm_password" type="password"> <span>Please confirm your password</span> </p> <p> <input type="submit" value="SUBMIT"> </p> </form>

''' But it did not work. I don't understand why.

1 Answer

Steven Parker
Steven Parker
215,984 Points

It looks like it should work.

For the code you show here, it should work either way because all the paragraphs are inside the form. But if any paragraphs containing spans were added outside the form it would no longer be the same.

For that reason, and because it also makes the intention clear, the use of "form span" as the selector would be a better choice.

If you'd like a more accurate and complete analysis of why it's not working, make a snapshot of your workspace and post the link to it here.

Note: when quoting code, the 3 marks are accents (```), not apostrophes (''').