Select inputs that doesn't have value attribute with querySelector

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?

Answers:

Answer

Try

document.querySelectorAll('input:not([value])')

This should return all the input that don't have the value attribute.

Answer

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" />

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.