There are several uses for purely recording:jquery grep () filter Traversal array$ (). Ready ( function () { var array = [1,2,3,4,5,6,7,8,9]; var filterarray = $.grep (array,function (value) { return value > 5;//filter out greater than 5 }); for (Var i=0;ijquery each() Filter Traversal array$ (). Ready ( function () {
Grepgrep () method for array element filter filtering
grep (Array,callback,invert)
Array: to be filtered arrays;
Callback: Handles each element in the array and filters the element, which contains two parameters, the first is the value of the current array element, and the index of the current array element, which is the indexed value of the element. This function should return a Boolean value. In addition, this function can be set to a string, which
The official note given by the filter (FN) in jquery is:Filters out the collection of elements that match the return value of the specified function the inside of the function computes each object once (as ' $.each ').If the called function returns false then this element is deleted, otherwise it will be preserved. There is no problem with this explanation, but the example given is problematic. Example isHT
Based on the elements in the obtained page, jQuery selectors can be divided into four categories: Basic selector, level selector, filter selector, and form selector. There are six filter selectors: simple filter selector, content filter selector, visibility
This is the 2 common methods used in jquery. Their 2 functions are completely different.If we use the find () method:var $find = $ ("div"). Find (". Rain");Alert ($find. HTML ()); will be output: Test 1If you use the filter () method:var $filter = $ ("div"). Filter (". Rain");Alert ($
This article mainly introduces jQuery's method of using the contains filter for exact matching, and analyzes the specific usage tips of the contains filter in combination with the example form, for more information about how jQuery uses the contains filter to implement exact match, see the following example. We will sh
Many times we can't find the element we want directly with the base selector and the hierarchy selector, and for this jquery provides a series of filter selectors to find the DOM elements that are needed more quickly. Many of the filter selectors are not CSS specifications, but jquery's own selector for the convenience of developers
The usage of the
Content Filtering selector: gets an element based on the text content in the element or its child element features. The text content can be fuzzy or absolutely matched for element locating.
JQuery selector details
Based on the elements in the obtained page, jQuery selectors can be divided into four categories: Basic selector, level selector, filter selector, and
(for example, $: each ). If the called function returns false, this element will be deleted,
Otherwise, it will be retained. Syntax format: filter (fn)Copy codeThe Code is as follows:
If the sub-element does not contain an ol element, set the font color of the element to blue.
4: has (expr) Method
This method is used to retain elements that contain specific descendants and remove those that do not contain specific descendants. This method creates a
element with the index greater than 5 in all Div,$ ("Div:lt (5)"), select the div element with index less than 5 in all Div.Note: The selection of the GT and LT combination: $ ("DIV:GT (3): LT (3)") is the result of obtaining a div with an index greater than 3 in the Div, and then getting a div with an index value less than 2 in the result set with an index greater than 3.7.animated$ ("div:animated") selects the div element in all div that is performing the animation effect.JQuery Selector (iv)
jquery filter Element functions1. FilteringMatch the second P element:$ ("button"). Click (function () {$ ("P"). EQ (1). CSS ("Color", "red");});Match the first LI element:$ ("button"). Click (function () {$ ("Li"). First (). CSS ("Color", "red");});Match the last element:$ ("button"). Click (function () {$ ("Li"). Last (). CSS ("Color", "red");});Checks whether the matched element contains the specified cl
jquery provides a powerful selector for getting objects. Here, I artificially divide the jquery selector into two parts: Select objects and filter criteria. The Selection object represents the object to get, and the filter criteria is to filter the objects that are obtained,
Find () searches for elements whose class is classname In the DIV element.
Filter () is used to filter the elements whose class is classname.
It is basically the find sub-element query, and the filter is the level query.
· The find function is used to query the child element of the current object set;· The filter
Name
Description
Explain
: Enabled
Match all available elements
To find all available input elements:$ ("input:enabled")
:d isabled
Match all unavailable elements
To find all input elements that are not available:$ ("input:disabled")
: Checked
Matches all selected selected elements (Checkboxes, radio boxes, etc., excluding option in select)
Find all selected check box elements:$ ("input:checked")
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 ")
Has (selector or DOM element) matches the Element Set Based on the selector or DOM element as the condition to retrieve whether the condition exists in the descendant of each element, create a new result set with the matching elements.
The following is an example:Copy codeThe Code is as follows:Copy codeThe Code is as follows:Certificate ('li'background .has('span'background .css ('background-color', 'red ');The result is as follows:
In this example, we can see that, when matching li, we need
1. Match elements According to a filter rule, which begins with the ":" sign, and is typically used to find a single element of a position in a collection element.$ ("Li:first") the first one$ ("Li:last") Last2. If you want to flexibly select any one of the tag elements from a set of tag element arrays, we can use: EQ (index)Where the parameter index represents the index number (that is, an integer), which starts at 0.If the value of index is 3, it me
This is the 2 common methods used in jquery.Their functions are completely different, while beginners are often misled.First we look at the. Find () Method:Now there is a page with HTML code inside it;Program codeclass="css"> class="rain" Class="rain"> If we use the find () method:var $find = $ ("div"). Find (". Rain"); alert ($ Find.html ());The output will be:If you use the filter () method:var $filter
jquery Visibility Filter selector1 Visibility Filter Selector$ (": Visible") Select all displayed elements$ (": Hidden") Select all hidden elements, including display= "none" element styles and hidden forms, visibility, etc.2 Ways to hide elementsthe value of CSS display is nonetype= form elements for "hidden"Width and height are displayed set to 0The ancestor el
example:Var arr = ["a", "B", "c", "d", "e"];Var arr2 = jQuery. map (arr, function (n, I ){Return (n. toUpperCase () + I );}); Www.2cto.comAlert (arr );Alert (arr2 );The execution result of the program is:A, B, c, d, eA0, B1, C2, D3, E4
3. $. grep (array, function (elementOfArray, indexInArray) [, invert])$. The grep () function removes unnecessary elements and acts as a filter. By passing its elements thro
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