:not() Selector

Selects all elements that do not match the given selector.

.not(selector)

selector SelectorA selector with which to filter by.

All selectors are accepted inside :not(), for example: :not(div a) and :not(div,a).

Additional Notes

The .not() method will end up providing you with more readable selections than pushing complex selectors or variables into a :not() selector filter. In most cases, it is a better choice.

Finds all inputs that are not checked and highlights the next sibling span. Notice there is no change when clicking the checkboxes since no click events have been linked.

JS
<div>
  <input type="checkbox" name="a" />
  <span>Mary</span>
</div>
<div>
  <input type="checkbox" name="b" />
  <span>lcm</span>
</div>
<div>
  <input type="checkbox" name="c" checked="checked" />
  <span>Peter</span>
</div>
HTML
$("input:not(:checked) + span").css("background-color", "yellow");
$("input").attr("disabled", "disabled");
DEMO

Looking for a Web Developer?

👋

Hi! I'm Basti, author of this site. If you are looking for a web developer with 15+ years of experience, holla at me!

Be it the good 'ol jQuery, vanilla JS or modern frameworks like Vue and Svelte, front- or backend, I can help you.

Just write me at jobs@jqapi.com :)