Reputation: 1464
I'm trying to loop through all the inputs in my form and if the input does not contain a value, then do a couple of things.
Here's my code so far,
$('input').each(function() {
if($(this+'[value!=""]')) {
$('.requiredMark').hide();
$(this).after(checkMark);
}
});
What am I doing wrong? Thank you
Upvotes: 0
Views: 89
Reputation: 9661
$('input').val(function(index,el){
if(el.length){
alert('Has value')
}
});
Upvotes: 0
Reputation: 571
Instead of doing $(this+'[value!=""]'), you can use
if($(this).val()===''){
//if the element has empty value, do something here
}
Upvotes: 1
Reputation: 7031
You can access your input field with $(this)
to get its value its $(this).val()
Upvotes: 0
Reputation: 3606
This should do the trick.
$('input').each(function(){
if($(this).val()){
$('.requiredMark').hide();
$(this).after(checkMark);
}
});
Upvotes: 0