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 Build an Interactive Website Form Validation and Manipulation Text Input Events

Adam Duffield
Adam Duffield
30,494 Points

Issue on Jquery


The task.. Select all inputs and on the 'keydown' event select 'this' and then show the next element.

My code:

$(".hint").hide() $(".hint").next(keydown()$(this));

it then says "Bummer! You did not call next() on $(this) and showed the returned element".

I've been following Jquery with no issue so far, but then on some tasks just when you think your getting the hang of things the task goes completely off what you've been taught and throws you too far in the deep end.

3 Answers

Hi Adam,

It looks like you're trying to run together the code from task 1 and task 2. I don't see a semicolon after $(".hint).hide()

In the second task they want you to select all inputs but you're still trying to select elements with a class of "hint". Then they want you to write a "keydown" event handler for those inputs. You're trying to pass that into the next() method. The only argument that you can pass into the next method is a selector to match against. We don't need to pass anything into the next method for this because they only tell us to show the next element with no requirement on what it has to be.

Here's the code I used to pass:


$('input').keydown(function () {

So we're selecting all the inputs and then assigning the keydown event to those inputs. The keydown event takes a handler function as it's argument.

Inside this function is where we can perform the task they want in response to a keydown event. In this case, they want us to show the element that is the next sibling to the input. $(this) refers to the input that received the keydown event.

Let me know if there's anything that's not clear.

Adam Duffield
Adam Duffield
30,494 Points

I think this will do the trick, and yeah that makes sense, it can be frustrating at times because i feel i know the code but the instructions sometimes arn't clear enough and you snowball and start writing even worse code until you end up asking for help! haha, but what you've said there makes plenty of sense, I'll try it out in a bit, currently having a problem where checking my code timesout.

Adam Duffield
Adam Duffield
30,494 Points

Works perfect, thanks for clearing that one up for me dude. Cheers.