Use the selector string 'div:not([data-value="0"])'
:
document.querySelectorAll('div:not([data-value="0"])')
.forEach(div => console.log(div));
<div data-value="0">0</div>
<div data-value="1">1</div>
<div data-value="2">2</div>
You can't use [attrib!=value]
in vanilla Javascript/CSS, unfortunately, you have to use :not
instead. (though, you can use [attrib!=value]
in jQuery)
To select <div>
s which have additionally have a data-value
attribute, but have one which is not 0
, add [data-value]
after the initial div
in the selector string:
document.querySelectorAll('div[data-value]:not([data-value="0"])')
.forEach(div => console.log(div));
<div data-value="0">0</div>
<div data-value="1">1</div>
<div data-value="2">2</div>
<div>3</div>