Sorry guys that i am asking a question that has long been answered. But I could not find the answer I needed.
The question is that i want to check value of input. If input after unfocus has one text or more (do something)
var inputLength = $('input').val();
if (inputLength.length > 1) {
$('span.input--madoka').addClass('myclass')
}
else {
}
Use blur() event to call your function when element loses focus
Here is example
$('#filter').blur(function() {
var inputLength = $(this).val();
if (inputLength.length > 1) {
console.log('has something');
// here you add whatever class you want to add to other element
} else {
console.log('has nothing');
// here some other action
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="filter" value="" />
You can do like this.
var empty = true;
$('#test').on('change', function(){
if($(this).val()!=""){
console.log('not empty');
} else {
console.log('empty');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Text : <input type="text" id="test" >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With