Home >>jQuery Tutorial >jQuery not() Method

jQuery not() Method

jQuery not() Method

jQuery not() method in jquery is used to returns elements that do not match a certain criteria and is often used to remove one or more elements from a group of selected elements.

Syntax:
$(selector).not(criteria,function(index))

Parameter Values

Parameter Description
criteria It is an Optional parameter and is used to specifies a selector expression, a jQuery object or one or multiple elements to be removed from a group of selected elements.
function(index) It is an Optional parameter and is used to specifies a function to run for each element in a group.
  • index – Used to the index position of the element in the set
Here is an Example of jQuery not() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").not(".text").css("background-color", "#24e387");
});
</script>
</head>
<body>
<h1>Welcome to Phptpoint</h1>
<p>This is a First Paragraph</p>
<p class="text">This is a Second Paragraph</p>
<p class="text">This is a Third Paragraph</p>
<p>This is a Fourth Paragraph</p>
</body>
</html>

Output:

Welcome to Phptpoint

This is a First Paragraph

This is a Second Paragraph

This is a Third Paragraph

This is a Fourth Paragraph