Detailed analysis of Filter Operations in jquery _ jquery

Source: Internet
Author: User
This article mainly introduces the filtering operations in jquery. For more information, see. 1. Filter Filtering

Name Description Example
Eq (index) Obtain the nth Element Obtain the Second Matching Element:
$ ("P"). eq (1)
Filter (expr)

Filters out a set of elements that match the specified expression.

Retain the elements with the select class:
$ ("P"). filter (". selected ")
Filter (fn)

Filters out a set of elements that match the specified function return value.

This function will calculate each object once (as in '$. each'). If the called function returns false, this element will be deleted, otherwise it will be retained.

The reserved sub-element does not contain ol elements:

$ ("P"). filter (function (index ){
Return $ ("ol", this). size () = 0;
});

Is (expr)

Note: This function returns a Boolean value instead of a jQuery package set.

Use an expression to check the selected element set. If at least one element matches the given expression, true is returned.

If no element matches, or the expression is invalid, 'false'. 'filter' is actually called internally. Therefore, the original rules of the filter () function are also applicable here.

Returns true because the parent element of an input element is a form element:
$ ("Input [type = 'checkbox']"). parent (). is ("form ")
Map (callback)

Convert a group of elements into other arrays (whether or not they are element arrays)

You can use this function to create a list, whether it is a value, attribute, CSS style, or other special form. You can use '$. map ()' to easily create

Create a list of values of each input element in form:

$ ("P"). append ($ ("input"). map (function (){
Return $ (this). val ();
}). Get (). join (","));

Not (expr) Deletes an element that matches the specified expression. Delete an element with a select ID from element p:
$ ("P"). not ($ ("# selected") [0])

Slice (start, end)

Select a matched subset Select the first p element:
$ ("P"). slice (0, 1 );

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.