Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Practice DOM Manipulation: Form Validation!
You have completed Practice DOM Manipulation: Form Validation!
Preview
This video covers one solution to the challenge.
Resources
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
I started by adding an event listener
to the form and made it listen for
0:00
the submit event.
0:02
This will be triggered as soon as
the user clicks the submit button.
0:03
Next up I created a conditional and
called the isvalidUsername function.
0:07
If this returns true,
0:12
I'm setting the className of
the label element to be valid.
0:14
I've selected the label element
with the closest method.
0:18
This works similarly to QuerySelector
using CSS selectors, but
0:21
selects the closest ancestor
that matches the selector.
0:25
In this case, that would be the direct
parent of the usernameInput.
0:29
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up