teelou teelou - 1 year ago 84
Javascript Question

$(":not(selector)") in plain/ vanilla javascript?

How can I write

in plain javascript?


var links = $('a:not(.not-lightbox-item a)', this);


<div id="links">
<div class="not-lightbox-item">
<a href="projects.html" class="button-back">
<span class="glyphicon glyphicon-hand-left glyphicon-circle-arrow-leftx" title="Back"></span>

<h2 class="heading item-heading">(Title) Ways of Something</h2>

<p>Lorem ipsum dolor sit amet <a href="#">Excepteur sint occaecat</a> cupidatat non proident</p>

<a href="images/banana.jpg" title="Banana">
<img src="images/thumbnails/banana.jpg" alt="Banana">
<a href="images/apple.jpg" title="Apple">
<img src="images/thumbnails/apple.jpg" alt="Apple">
<a href="images/orange.jpg" title="Orange">
<img src="images/thumbnails/orange.jpg" alt="Orange">

Any ideas?

Answer Source

Why not toggle a class which has the selector applied to it in in pure CSS?

.className {
  color: blue;

var myitem = document.querySelector('.item')

I would resort to :not only if I had no control over the HTML.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download