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 trial

JavaScript

form 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.

This 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 :)

12 Answers

nevermind 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
Larry Kasaija
3,081 Points

Thank 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
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Glad you figured it out Domenico. If you have any more issues please let us know!

Miguel Zarate
Miguel Zarate
5,024 Points

Hi, sorry, I ran into the same issue, can I ask why you need to add the p tag?

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

You should just be able to get away with $("#email").

Miguel Zarate
Miguel Zarate
5,024 Points

Hi Andrew, that makes sense... thanks for the prompt reply... cheers mate.

I 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
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Post 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
Rhiannon Hood
5,429 Points

This 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
Larry Kasaija
3,081 Points

I 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")

This 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
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi 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
David Langley
10,965 Points

Hey 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
Andrew Chalkley
Treehouse Guest Teacher

In 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?