The use of jquery traversal not

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.