• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2621
  • Last Modified:

JavaScript: Exclude items from document.querySelectorAll

var items = document.querySelectorAll('.x .y .z');

Open in new window

That selects all elements with the matching CSS pattern.  I do NOT want to select any elements that contain the class: "skip".

So this should match:
<div class="x"><p class="y"><em class="z"></em></p></div>

But this should NOT match:
<div class="x"><p class="y"><em class="z skip"></em></p></div>

How can this be done with JavaScript or jQuery?
0
hankknight
Asked:
hankknight
1 Solution
 
GaryCommented:
You can use :not()

e.g.
document.querySelectorAll('.x:not(.skip),.y:not(.skip),.z:not(.skip)');
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now