jQuery check if <input> exists and has a value
The input won't have a value if it doesn't exist. Try this...
if($('.input1').val())
You could do:
if($('.input1').length && $('.input1').val().length)
length
evaluates to false
in a condition, when the value is 0
.
You can do something like this:
jQuery.fn.existsWithValue = function() {
return this.length && this.val().length;
}
if ($(selector).existsWithValue()) {
// Do something
}