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 trialLuis Chiappe
Courses Plus Student 10,636 PointsFunction(email) vs $("#email");
Why on the function validate use email as parameter and doesn't use inside the function $("#email"); I mean which is the difference between those?
1 Answer
Don McCurdy
2,345 PointsThey are actually not the same thing. $("#email")
is really just an HTML element on the page: the little textbox you're typing into. On the other hand email
is the the content that was typed into that textbox: the email address. To break that down a bit:
$("#email")
is the visible interface you can type into:
<input type="text" id="email">
email
is the content of that textbox, which you can get by asking the textbox for it's content using .val()
:
var email = $("#email").val();
// now 'email' == "john.doe@gmail.com" or whatever you typed
So to make sure the content is valid, you would use the content, email
. To do something related to the interface (like changing colors) you would use the HTML textbox, $("#email")
.