Jquery filter elements (1) and jquery filter elements

Source: Internet
Author: User

Jquery filter elements (1) and jquery filter elements

. Eq ()
Reduce the set of matching elements to the element of the specified index.
. Eq (index)
Index is an integer that indicates the position of an element, based on 0.
$ ("Li" ).eq(2).css ('background-color', 'red ')
// Select the third element to change the background to red.
. Eq (-index)
-Index is an integer that indicates the position of an element and starts from the last element in the set.
$ ("Li" ).eq(-2).css ('background-color', 'red ')
// Select the second to last element and change the background to red.


. Filter ()
Filter the matching expressions in the element set or the element set tested by the function.
. Filter (selector)
A selector string used to match elements.
$ ('Lil'). filter (': even'background .css ('background-color', 'red ');
// Turns the background of the element with an odd number of rows into red.
. Filter (function (index ));
Function (index)
A function is used to test each element in the set. This is the current DOM element.
$ ("Li"). filter (function (index ){
Return index % 3 = 2;
Background .css ('background-color', 'red ');
Change the multiples of the third and sixth three to red.
. Filter (element)
One or more DOM elements match the current element set.
$ ("Div"). filter (". mddle" ).css ("border-color", "red ");
Obtain the element that contains the. middle selector in the div and convert the background to red.
. Filter (jQuery object)

JQuery object type: object
Used to further filter the current element set.
$ ("Div"). filter (function (index ){
Return index = 1 | $ (this). attr ("id") = "fourth ";
}).Css ("border", "3px double red ")
Obtain the element in the div that contains an index value equal to 1 or the id selector is fourth, and change it to a border.

 


. First ()
Obtain the first element in the matched element set.
This method does not accept any parameters.
$ ("Li" ).first().css ("background-color", 'red ');
// Find the first element in li and change the background color to red.


. Has ()
Filter those that match the element set with matched selectors or DoM elements.
. Has (selector)
Selector: a selector string used to match elements.
. Has (contained)
Contained is used to match the DOM element of an element.
Certificate ('li'background .has('ul'background .css ('background', 'red ');
Filter out the elements containing ul in li.
. Is ()
Determines whether the element set that is currently matched is a selector, DOM element, or jQ object. If there is a match, true is returned.
. Is (selector)
A string that contains a selector expression used to match elements.
. Is (function (index ))
A function is used to test the index position of the element... index in the set. This indicates the current element.
. Is (jQuery object)
Existing element to match the current element.
. Is (element)
Element is a DOM element Used for matching.
$ ("Input [type = 'checkbox']"). parent (). is ("form ");
Determines whether the parent level of an element whose form type is checkbox is 'form'. If yes, true is returned, or false is returned.
. Last ()
Obtain the last matching element.
This method does not accept any parameters.
$ ("Li" ).last().css ("background-color", 'red ');
// Find the last element in li and change the background color to red.
. Map ()
Use a function to match every element in the current set. Generates a new object.
. Map (callback (index, domElemnt ))
Callback (index, domElemnt)
A function object.
$ ('Input'). map (function (){
Return $ (this). val ();
}) Obtain each value in the input set.
. Not ()
Removes the specified element from the matched element set.
. Not (selector)
Selector a selector used to match elements.
Certificate ('li'0000.not(('.notli'00000000.css ('background-color', red );
The background color except with the. notli selector is set to red.
. Not (elements)
One or more DOM elements to be removed from the element set.
$ ('Lil'). not (': event'background .css ('background-color', 'red ')
Items 2 and 4 in the list are red. Because the selector does not match.
$ ('P'). not ($ ("div p. selected "))
Remove the element that meets "div p. selected" from the section set.
. Not (function (index ))
Unction a function is used to test each element in the set. this refers to the current DOM element.
. Slice ()
Filters Matching Element Sets Based on the specified subscript range to generate an object.
. Slice (start [, end])
Start is an integer that starts counting from 0. Start subscript. If it is a negative number, it can start from the end.
End: an integer that starts counting from 0. End the subscript, if not written until the end.
Certificate ('li'mirror.slice(2).css ('background-color', 'red ')
From the third in the Set, the background is all white.
$ ('Lil'). slice (2, 42.16.css ('background-color', 'red ');
The background of the third and fourth items in the list is set to red.

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.