How to select empty inputs (value=“”) using jQuery

后端 未结 7 1569
遇见更好的自我
遇见更好的自我 2020-12-03 00:31

How can I check for empty values of (required) input fields within a section, and then add a class to them on an event, using jQuery? So far, I have tried:

7条回答
  •  旧时难觅i
    2020-12-03 00:55

    jQuery('#sender_container input.required[value=""]').addClass("error");
    

    You can try this:

    $('input:not([value!=""])').addClass('error');
    

    DEMO

    Note: This answer should not be used, and the only reason it wasn't deleted is so it can be learned from.

提交回复
热议问题