getaway
getaway

Reputation: 8990

checking if a field is empty in jquery(js)?

If a field is empty when it is blurred (loses focus) I want to remove an image:

Here's the beginning code:

$('#type').keyup(function(){
   $('#image').show();

 $("#type").blur( function() {

// i wanted to check here if #type field is empty as well before hiding?

        $('#image').hide();
});

Upvotes: 1

Views: 202

Answers (1)

gblazex
gblazex

Reputation: 50109

$("#type").blur( function() {
  if (this.value === '') {
    $('#image').hide();
  }
});

Upvotes: 4

Related Questions