Solved

JavaScript: Exclude items from document.querySelectorAll

Posted on 2014-03-14
1
2,104 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

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
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)

828 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