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?
LVL 16
hankknightAsked:
Who is Participating?
 
GaryConnect With a Mentor Commented:
You can use :not()

e.g.
document.querySelectorAll('.x:not(.skip),.y:not(.skip),.z:not(.skip)');
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.