I am checking for each required fields in a form. I tried this but it only works for the first input. How can I make it work for each input?
if($('[required]').val() != ''){ $('.button1').fadeIn(0); $('.button2').fadeOut(0); }else{ $('.button1').fadeOut(0); $('.button2').fadeIn(0); }
EDIT: for more context, here's another function I had below this to apply whenever they change and HTML code.
$('[required]').change(function() { if($('[required]').val() != ''){ $('.button1').fadeIn(0); $('.button2').fadeOut(0); }else{ $('.button1').fadeOut(0); $('.button2').fadeIn(0); } });
HTML
I have bunch of inputs like these:
buttons:
button 2
So I want to check for empty fields when it the page loads and whenever they change.
BTW, I don't have a form tag around these because it's for mobile and didn't think it's really necessary, if that makes any difference.
Thanks again!