Milford School (JQuery projects)


How do I set #email and #password equal to blank/no input. I'm on one of the jquery practice exercises and I need help with this. Thank you very much.

e.g. I tried saying
if( "#email" === "" ) {

Please enter your email

I tried the similar thing with #password also.


May we assume that both of these are input fields (or a textarea and an input)?

That being determined,


When .val() has no parameter, it is a getter; and, when it has a parameter it is a setter. An empty string qualifies as a parameter.

We can cache the two form element objects for easy referencing without a selector each time we need to poll it.

var $email = $('#email');
var $password = $('#password');

Do this at load time and refer only to the variables, afterward.

Your program is going to have an event listener on either a button event or a 'submit' event. This will trigger the handler function which may contain something like,

        if ($email.val()) {
            // run handler code on `$email.val()`
        } else {
            // run error code


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.