back to Overview

.not()

Returns a new list that contains only those elements that do not match the given selector, callback function or have the given index.
Web module only.

Syntax Variants

list.not()
list.not(selector)
list.not(filterFunc)
list.not(index)

Parameters

selector
any selector valid for $(), including CSS selectors and lists.
Selectors are optimized for '*', '.classname', 'tagname' and 'tagname.classname'. The performance for other selectors depends on the number of matches for the selector in the document. Default is '*', which removes all elements (but keeps other nodes such as text nodes).
filterFunc
a function(node) returning true for those nodes that should be removed.
index
the index of the element to remove. All elements with other index will be kept. If there is no element with this index in the list, the returned list is identical to the original list.
(return value)
a new list containing only elements not matched by the selector/function/index.

Description

Returns a new list that contains only those elements that do not match the given selector, callback function or have the given index. If no parameter has been given, the method removes all HTML elements and keeps the rest (same as '*').

When you use selectors, please note that this method is optimized for the four simple selector forms '*', '.classname', 'tagname' and 'tagname.classname'. If you use any other kind of selector, be aware that selectors that match many elements can be slow.

Example

Returns only those list elements have the classes 'listItem' but not 'myClass':

var myLis = $('li.listItem').not('.myClass');

Example

Returns a list of all elements except forms:

var forms = $('#content *').not('form');

See also..

  • only() is the opposite of not() - it keeps all elements that match the selector.

Comments

comments powered by Disqus

back to Overview

Functions