JQuery Traversal-Filter---first--last---eq--not--filter method (25)

Source: Internet
Author: User
Tags manual
the scope of the abbreviation search element

The three most basic filtering methods are: First (), Last (), and EQ (), which allow you to select a specific element based on its position within a set of elements.

Other filtering methods, such as filter () and not (), allow you to select elements that match or do not match a specified criterion. JQuery First () method

The first () method returns the initial element of the selected element.

The following example selects the first <p> element inside the first <div> element: an instance

$ (document). Ready (function () {
  $ ("div p"). First ();
});

Try the JQuery last () method yourself

The last () method returns the final element of the selected element.

The following example selects the last <p> element in the last <div> element: instance

$ (document). Ready (function () {
  $ ("div p"). Last ();
});

Try the jQuery eq () method yourself

The EQ () method returns the element with the specified index number in the selected element.

The index number starts at 0, so the first element's index number is 0 instead of 1. The following example selects the second <p> element (index number 1): instance

$ (document). Ready (function () {
  $ ("P"). EQ (1);
});

Try the jQuery filter () method yourself

The filter () method allows you to specify a standard. Elements that do not match this standard are removed from the collection, and the matching elements are returned.

The following example returns all the <p> elements with the class name "Intro": instance

$ (document). Ready (function () {
  $ ("P"). Filter (". Intro");
});

Try the JQuery not () method yourself

The Not () method returns all elements that do not match the criteria.

tip:The Not () method is the opposite of filter ().

The following example returns all the <p> elements without the class name "Intro": instance

$ (document). Ready (function () {
  $ ("P"). Not (". Intro");
});

Try the jQuery Traversal reference manual Yourself

For all the jquery traversal methods, please visit our jquery Traversal reference manual.

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.