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!

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 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
228,026 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 (''').