Remove the paragraph with the ID "selected" from the collection that contains all the paragraphs:
$ ("P"). Not ("#selected")
Definition and usage
Not () removes the element from the matching element collection.
Syntax 1
. Not (selector)
| Parameters |
Description |
| Selector |
A string value that contains the selector expression used to match the element. |
Syntax 2
. Not (element)
| Parameters |
Description |
| Element |
One or more DOM elements that need to be removed from the matching set. |
Syntax 3
. Not (function (index))
| Parameters |
Description |
| function (Index) |
The function used to detect each element in the collection. This is the current DOM element. |
Detailed description
Given a jquery object that represents a collection of DOM elements, the. Not () method constructs a new jquery object with a subset of the matching elements. The applied selector detects each element, and the element that does not match the selector is included in the result.
Consider the following page with a simple list:
<ul> <Li>List Item 1</Li> <Li>List Item 2</Li> <Li>List Item 3</Li> <Li>List Item 4</Li> <Li>List Item 5</Li></ul>
We can apply this method to a list item set:
$ (' Li '). Not (': even '). css (' background-color ', ' red ');
Remove a specific element
The second version of the. Not () method allows us to remove elements from a matching set, assuming that we have previously found these elements by other means. For example, imagine a list that has an ID applied to one of the items:
<ul> <Li>List Item 1</Li> <Li>List Item 2</Li> <LiID= "Notli">List Item 3</Li> <Li>List Item 4</Li> <Li>List Item 5</Li></ul>
We can use the native JavaScript function getElementById () to read the third list item and then remove it from the JQuery object:
$ (' Li '). Not (document.getElementById (' Notli ')). CSS (' background-color ', ' red ');
The use of jquery traversal not