?
Solved

JavaScript: Exclude items from document.querySelectorAll

Posted on 2014-03-14
1
Medium Priority
?
2,379 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 58

Accepted Solution

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

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

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

743 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