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

More elegant solution using .on('input', function)

Wouldn't:

var $pwInput = $('#password');
$pwInput.on('input', function(){

    if($pwInput.val().length < 8) $(this).next().show();
    else $(this).next().hide();
    console.log();

});

be a more elegant solutions than attaching to the key up event. Since the value would be checked everytime a is pressed even if the user is not entering the form.

1 Answer

Hi Chris,

I think I'd have to agree with you, actually. Keyup will fire on any key regardless of whether or not it changes the input, where the input event only fires when the value of the input has changed. I think keyup was likely used more frequently to support older browsers.