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 trialDomenico Colandrea
3,379 Pointsform validation > code challenge: modifying attributes NEED HELP PLEASE
OK . So the question says,
"In jQuery add the class of 'valid' to the input with the id of 'email'"
my answer is..
$("#email input").addClass("valid");
What am I doing wrong? So far I've been doing great and really grasping everything you discuss but I can't figure out what I'm not getting in this one and it's making me go crazy LOL. Please help.
12 Answers
Domenico Colandrea
3,379 Pointsnevermind i just figured it out...i wasn't including the <p> ..
$("p input#email").addClass("valid"); <---correct answer
i went to the jquery website and was reading the api section and realized i should put the p tag .. lol
sorry im a newbie to query..love your tuts tho btw :)
Larry Kasaija
3,081 PointsThank for sharing. 8 months later I someone runs into the same problem. Big thanks to you, I didn't have to spend a lot of time on this. I have found this forum very helpful.
Andrew Chalkley
Treehouse Guest TeacherGlad you figured it out Domenico. If you have any more issues please let us know!
Miguel Zarate
5,024 PointsHi, sorry, I ran into the same issue, can I ask why you need to add the p tag?
Andrew Chalkley
Treehouse Guest TeacherYou should just be able to get away with $("#email").
Miguel Zarate
5,024 PointsHi Andrew, that makes sense... thanks for the prompt reply... cheers mate.
Brent McCarthy
2,736 PointsI tried it with and without the p tag and didn't get it to work. I tried all of the above. What am I doing wrong?
Andrew Chalkley
Treehouse Guest TeacherPost your code in so we can take a look.
Use the markdown cheetsheet below the comment box to see how to format it.
Rhiannon Hood
5,429 PointsThis is what I entered and it's not accepting it:
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="app.js">
$("input #email").addClass("valid");
</script>
Larry Kasaija
3,081 PointsI am fairly new here as well. Try adding "p" before input, like this: $("p input#email").addClass("valid"); Picked this up from Domenico. And it worked for me. If it doesn't work for you, go for this one: $("#email").addClass("valid")
Ken Francis
Courses Plus Student 4,224 PointsThis is my code:
var $email = $("#email input");
$email.addClass(".valid");
Is there a reason this isn't working? I'm using code that was shown in the video. The error is telling me "You need to call the addClass method". The prompts could be more specific. Is it because I put #email before input?
Andrew Chalkley
Treehouse Guest TeacherHi Ken Francis,
What your selecting in this is a input
in a container with the id of #email
...
<div id="email">
<input type="text">
</div>
You need to select the input with the id of email
.
<input type="text" id="email">
Hope that helps.
David Langley
10,965 PointsHey Andrew,
That makes sense to me, however, how is that different to the video where when making the var we needed $(".submit input")? Is this a class vs Id thing or ??
thanks!
Andrew Chalkley
Treehouse Guest TeacherIn the video we're selecting an input within a paragraph of the class sumbit.
<p class="submit">
<input type="submit" value="Submit" class="btn-submit">
</p>
The CSS selector is .submit input
if the input had the id of #submit
we could just use that.
The code challenge is asking you to select an element with an id of #email
.
Does that make sense?
Peaches Stubbs
21,320 PointsPeaches Stubbs
21,320 PointsThis was helpful thanks for posting this. NOt sure why I had to use the p tag maybe the ip is on that element. But thanks :)