I'm using:
document.querySelectorAll('input[value=""]')
But it's not selecting inputs that doesn't have the attribute value
.
How can I select all inputs that doesn't have a value ''
, and that doesn't have the attribute value?
I would like to do that without jQuery and without any additional function, would that be possible only using querySelectorAll
?
I'm using:
document.querySelectorAll('input[value=""]')
But it's not selecting inputs that doesn't have the attribute value
.
How can I select all inputs that doesn't have a value ''
, and that doesn't have the attribute value?
I would like to do that without jQuery and without any additional function, would that be possible only using querySelectorAll
?
- That's a bit confusing. You want to select those inputs which have values, or the ones that don't have? – LcSalazar Commented Oct 31, 2014 at 19:38
2 Answers
Reset to default 16Try
document.querySelectorAll('input:not([value])')
This should return all the input
that don't have the value
attribute.
You can use this:
document.querySelectorAll('input:not([value]):not([value=""])');
get all inputs that doesn't have attribute "value" and the attribute "value" is not blank
var test = document.querySelectorAll('input:not([value]):not([value=""])');
for (var i = 0; i < test.length; ++i) {
test[i].style.borderColor = "red";
}
<input type="text" />
<input type="text" value="2" />
<input type="text" />
<input type="text" value="" />
<input type="text" />