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 trialDavid Service
12,928 PointsUse the Created Variables on the Statements in our code?
When Andrew creates a pair of variables to contain the elements we keep targeting,
var $password = $(“#password”);
var $confirmPassword = $(“#confirm_password”);
we can use them in our functions without a problem.
My question is, can't we also use these variables in our statements later on in the code?
For instance, can we change this:
$(“#password”).focus(passwordEvent).keyup(passwordEvent);
$(“#confirm_password”).focus(confirmPasswordEvent).keyup(confirmPasswordEvent);
Into this?
$password.focus(passwordEvent).keyup(passwordEvent);
$confirmPassword.focus(confirmPasswordEvent).keyup(confirmPasswordEvent);
Not really an life-or-death issue, but just curious.
Many thanks,
David
David Service
12,928 PointsDavid Service
12,928 PointsJust watched a few more minutes into the video, and Andrew went right ahead and did exactly what I was asking about.