Gregor Gregor - 7 months ago 22
Javascript Question

How to recheck if Input is still empty

I'm struggling with this basic jQuery and I hope you can help out.

I have the following code which hides

#test
if it's empty. How do I change to show now, if the input is not longer empty.

jQuery(function ($){
if($("#email").is(":empty")){
var test = $("#test");
$(test).hide();
}
});

Answer

Try following

$('#email').keyup(function(event) {
   var test = $('#test');
   if($(this).val() === '') {
      test.hide();
   } else {
      test.show();
   }
});
Comments