I have a class .address
added to a couple of my inputs. Basically, I want to check if all of them have been filled out. I know this is possible by iterating over the class like this:
var valueForAll = true;
$('.address').each(function (i, obj) {
if ($(this).val() == "") {
valueForAll = false;
}
});
if (valueForAll == true) {
// Do something
}
else {
// Do something else
}
I don't think this is an ideal solution though. So I found the :empty
selector. Which works like this:
$("input:empty").length == 0;
However, doing this for my class always shows a length of 6. I don't know why.
$(".address:empty").length == 0;
Edit:
This is not a duplicate question as this one attached from @chrispbacon. This question focuses on how to check if all inputs of a class have been filled, not all elements inside a div. I cannot find any thread on Stack Overflow that focuses on how to check if all inputs have a value of a class without iterating over the class.