Reputation: 1885
Is there a way to get all the elements that don't start with the id foo
in JavaScript?
I tried the following:
var elements = document.querySelectorAll('[id!=foo]');
That doesn't work.
Basically I want the opposite of:
var elements = document.querySelectorAll('[id^=foo]');
Upvotes: 1
Views: 1290
Reputation:
Use the :not()
selector:
document.querySelectorAll(":not([id^='foo'])");
Upvotes: 4
Reputation: 7916
You can use the :not
pseudo selector to match everything except [id^="foo"]
:
var elements = document.querySelectorAll(':not([id^=foo])');
Upvotes: 2
Reputation: 35096
Just select all and then filter out the one with the id
document.querySelectorAll("*").filter(...)
Upvotes: 0