jQuery check if any text input has value
问题 I want to ask if there's a better way in jQuery to select multiple text input then check if any of them has a value. Here's my code: if ($("#reference").val() != "" || $("#pin").val() != "" || $("#fName").val() != "" || $("#mName").val() != "" || $("#datepicker").val() != "") { /*logic goes here */ } 回答1: You could do like below: if ($("#reference,#pin,#fName,#mName,#datepicker").filter(function() { return $(this).val(); }).length > 0) { //.. } Using a common function like the following would