jQuery :not Selector

The jQuery :not selector selects all the elements which are not specified. It can be useful when you want to select all the items of a group element except the single one or multiple. After selecting the element, you can apply the CSS or any other effects to the element.

jQuery :not Selector Syntax

The syntax of the selector is given below.

Syntax
$(“:not(selector)”)

It takes a single value as an argument which is a string. The description of the selector is given below.

Parameter Description

Sr No Parameter Name Description
1 selector
  • A selector is the element to specify not to select. You can use a single element or comma-separated multiple-element name, class or id.
  • Required

Let’s now understand the selector with the example given below.

jQuery :not Selector with Single Class Selection

A table contains many rows with a multiple numbers of cells to add content. If you want to highlight all the rows except the selected one, you can use the example given below. It selects only the single row of the table to remove from the selection and apply CSS color.

Example

Test it Live

Output

Sr No Computer Accessories Quantity
1 Touchpad 19
2 Mouse 12
3 Monitor 23
4 Mouse Ball 14
5 Mouse Scroller 11

The above example contains the table and the button element. You have to click the button given above to apply the ‘orange’ color to the rows. Only the specified row class is not selected for the text color.

Select Multiple Class of Element with the Selector

In addition to a single element select, the selector also allows you to select multiple elements comma-separated. You have to specify the element name, class name or id of the element to select. See the example given below to add multiple class names of the element.

The example contains the list elements element with computer accessories names.
Example

Test it Live

Output


  • Printer
  • Keyboard
  • Photocopy Machine
  • Laser Printer
  • Scanner
  • Mouse

The above example highlights the matching element when you click the button. It applies ‘red’ color the list items using the selector.