I
I
Ivan Ilyasov2015-10-19 17:58:40
JavaScript
Ivan Ilyasov, 2015-10-19 17:58:40

Why doesn't focusout c input work?

It seems to work .. What am I doing wrong?

$("input[name='name']").focusout(function(){
        if($(this).val() = ''){
    $(this).val("new_val");
        }
      });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Inchin ☢, 2015-10-20
@IvanIlyasov

I understand that you were interested in blur, not focusout.
And also you don't know that = is an assignment sign, but == is a comparison. In general, you can shorten the entry:

$("input[name='name']").blur(function(){
   if(!$(this).val())  $(this).val("new_val");
});

or
$("input[name='name']").blur(function(){
   $(this).val() || $(this).val("new_val");
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question