:not() Selector - Javascript jQuery Selector

Javascript examples for jQuery Selector:not

Description

The :not() selector negates the selection.

Syntax

Parameter Description
selector Required.

The following code shows how to select all <p> elements except those with class="intro":

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("p:not(.intro)").css("background-color", "yellow");
});/*from   w  ww.j ava2s  .  c o  m*/
</script>
</head>
<body>

<p class="demo">This is a test.</p>

<p class="intro">This is a test.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>

<p>Who is your favourite:</p>

<ul class="intro">
  <li>A</li>
  <li>B</li>
  <li>C</li>
</ul>

</body>
</html>

Related Tutorials