Solved

JavaScript: Exclude items from document.querySelectorAll

Posted on 2014-03-14
1
1,932 Views
Last Modified: 2014-03-14
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
Comment
Question by:hankknight
1 Comment
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39929995
You can use :not()

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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now