Class Array Operations in jQuery objects

Source: Internet
Author: User

Let's see what available methods jQuery provides for us:
Size (): Obviously, it should be the number of elements in the returned package set, for example, $ ('A'). size () indicates the number of link elements;
Get (index): If no index is specified, all elements in the packaging set are taken by default and returned in array form in js. If index is specified, the subscript is the element corresponding to index, for example, $ ('img [title] '). get (0) returns the first img element containing the attribute title, which is also equivalent to $ ('img [title] ') [0];
Index (elem): returns the subscript of the elem element in the packaging set. If this element is not found,-1 is returned;
Add (String | elem | Array): adds the elements in the parameter to the packaging set. If the parameter is a jQuery selector, all matching objects are added to the set, if it is an html element, add the element array obtained through the clean method to the set. If it is a dom element or dom element array, add it directly to the set; note that the returned value is the added package set. For example, $ ('img [alt] ', 'img [title]') is equivalent to $ ('img [alt] '). add ('img [title] ') returns the img elements that contain the alt attribute or the img elements that contain the title attribute;
Not (String | elem | Array): deletes elements that meet the parameter conditions in the packaging set. Note that the parameter can only be a filter expression, that is, an expression starting with "[" or, for example, $ ('img [title] '). not ('title * = puy') indicates that the img element containing the title attribute is returned, and the title attribute of these elements contains puy text. The filtered packaging set is returned;
Filter (String | function): If the input parameter is of the String type, the expression must also be a filter expression to delete all elements that do not match the selector from the package; if a function is input, every element in the packaging set calls this function. If this function returns false, this element is deleted from the packaging set, in the function, you can use the this keyword to call the elements of the method called in the current packaging set; for example, $ ('td '). filter (function () {return this. innerHTML. match (/^ "d + $/)}) returns all td elements whose content is a number;
Slice (begin, end): Creates and returns a new package set, which is a continuous part of the original package set, the first element of the new package set is the element at the begin position of the original package set, and the last element is the former element of the end position element. Of course, the end element can not be specified, it will be extended to the end of the original package set; for example, $ ('*'). slice (): select all elements on the page, and then store the new package set containing the third element of the original package set. Pay attention to this $ ('*'). get (2) is different. The returned result is an element, and the slice method returns the package set, so as to have the operation of the package set;
Childen (): returns the new packaging set (excluding text nodes) consisting of all the different child elements of the original packaging set element, such as $ ('div '). children () returns a new packaging set composed of child elements under all div elements. If a parameter is specified, this parameter is also a filter expression;
Contents (): return the content of the original package set element to the new package set (which can contain text nodes). Note that this method does not accept parameter filtering;
Next (): return the new packaging set consisting of all the unique next sibling elements of the original packaging set element. If a parameter is specified, this parameter is also a filter expression; for example, $ ('div # somediv '). next () returns the package set of the next sibling element containing the div element whose id is someDiv. If a parameter is specified, this parameter is also a filter expression;
NextAll (): returns the new wrapper set of all subsequent siblings that contain the original wrapper set elements, for example, $ ('div # somediv '). nextAll () returns the new packaging set of the sibling element behind the div element whose id is someDiv. If a parameter is specified, this parameter is also a filter expression;
Parent (): return the new packaging set with the unique direct parent element of all elements in the original packaging set. If a parameter is specified, this parameter is also a filter expression;
Parents (): return the new packaging set of the ancestor elements of all elements in the original packaging set. If a parameter is specified, this parameter is also a filter expression;
Prev (): returns all the unique new packaging sets composed of the last sibling element of the original packaging set element. If a parameter is specified, this parameter is also a filter expression;

PrevAll (): returns the new packaging set of all the preceding sibling elements that contain the original packaging set element. If a parameter is specified, this parameter is also a filter expression;
Siblings (): returns a new packaging set consisting of all unique sibling elements in the original packaging set element. If a parameter is specified, this parameter is also a filter expression;
Find (String): returns a new package that contains all elements in the original package that match the input selector expression, in addition, the descendant of elements in the original package set will also be introduced into the new package set;
Contains (text): return a new packaging set consisting of elements that contain the text string passed in by the text parameter;
Is (String): If the package contains String matching elements, true is returned; otherwise, false is returned;
Clone (copyHandle): If the input parameter is true, the event is copied together. Otherwise, the event is not copied to form a new packaging set;
End (): called in the jQuery command chain to return to the previous package set;
AndSelf (): combines the two recently generated packages in the command chain;
The operations on the packaging elements are summarized here. If anything is wrong, please point it out for your reference.

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.