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 Modifying Attributes

Nthulane Makgato
PLUS
Nthulane Makgato
Courses Plus Student 19,602 Points

Modifying Attributes in JQuery video

I have just watched a video on modifying attributes but there are certain lines of code that I don't understand.

                    var $submit = $(".submit input");
        function requiredFilledIn(){
            if(true) $submit.attr("disabled","disabled");
            else $submit.removeAttr("disabled");
                    }

                    $("#form span").hide();
        $("input,textarea").focus(function(){
            $(this).next().fadeIn("slow");
        }).blur(function(){
            $(this).next().fadeOut("slow");
        }).keyup(function(){
            //Check all required fields.
            requiredFilledIn();
        });

        $("#email").keyup(function(){
             //check for a valid email.
             if(false) $(this).next().removeClass("error")addClass("valid");
             else $(this).next().removeClass("valid").addClass("error");
        });

        requiredFilledIn();

So the if/else statements in the requiredFilledIn function determine whether the ".submit input" is submitted but they are determined by whether there are inputs in the ".submit input" fields. My question is, how does the "requiredFilledIn()" know that the input fields are empty or filled?

I hope that the extract of code that I gave you is enough. Thanks for your help.