Collation collection _jquery based on jquery selector

Source: Internet
Author: User
Tags prev first row

jquery Object Access
1. Each (callback): Executes a function with each matching element as context, return false; Stop loop; return true; skip to Next loop.

Here's an example:

Copy Code code as follows:

$ ("img"). each (function () {
$ (this). Toggle ("example");
})

2. Size () is the same as length, which returns the number of elements in the jquery object.

$ ("img"). Size () or $ ("img"). length;

3, Get (): Gets all the matching DOM elements collection (note that the return is a DOM object, not a jquery object)

Copy Code code as follows:

$ ("img"). Get (). reverse ();

4, Get (index): Obtain one of the matching elements. The index representation matches the first few elements, and using the Get (Index) method allows you to manipulate an actual DOM element.

$ ("img"). Get (0);//Gets the first matching IMG element

$ (this). Get (0) and $ (this) [0] equivalent

5. Index (subject): Searches for the element that matches the object represented by the parameter and returns the index value of the corresponding element.

Selector-Basic
Selector1,selector2,selectorn merges the matching elements together and returns

Copy Code code as follows:

$ ("Div,span,p.myclass");

Notice the difference between several similar grammars here:

1, $ ("span", this)

Like what:

Copy Code code as follows:

$ ("Div.foo"). Click (function () {
$ ("span", this). AddClass ("Bar");
});

2, $ ("Div#hi"), $ ("P.intro")

Like what:

Copy Code code as follows:

$ ("Div#hi"). CSS ("Color", "red");

3, $ ("form input")

Like what:

Copy Code code as follows:

$ ("form input"). CSS ("Border", "5px solid Red");

To distinguish the different meanings of the above several similar forms.

Selector-Hierarchy
1.ancestor descendant matches all descendant elements under a given ancestor element

$ ("div input");//div all input

2.parent > Child match all children under a given parent element

$ ("div > Input";//child elements under parent element

3.prev + next matches all next elements immediately following the Prev element

$ ("div + span")//span immediately following Div

4.prev ~ Siblings All siblings elements after the Prev element

$ ("form ~ input")//Find all input elements with the form's peers

Selector-Simple
1.:first matches the first element found

$ ("Tr:first")//Find first row in table


2.:last matches the last element found
$ ("tr:last")//Match the last element found


3.:not (selector) removes all elements that match a given selector
Ps:jquery 1.3, complex selectors have been supported (for example:: Not (Div a) and: not (Div,a))
$ ("Input not (: checked)")//all unselected input elements


4.:even matches all elements with an even number of index values, counting from 0 start
$ ("Tr:even")/even rows in lookup table


5.:odd matches all elements with an odd index value, counting starting from 0
$ ("tr:odd")/Find odd rows in table


6.:eq (index) matches an element of a given index value
$ ("Tr:eq (1)")/Find second row


7.:GT (index) matches all elements that are greater than the given index value
$ ("tr:gt (0)")//Find all rows greater than 0


8.:LT (index) matches all elements that are less than the given index value
$ ("Tr:lt (2)")//Find all rows less than 2


9.:header matches a header element such as H1,h2,h3
$ (": Header"). CSS ("background", red);//all headings plus background color


10.:animated matches all elements that are performing an animation effect


Selector-Content:
1.:contains (text) matches the element that contains the given text
$ ("Div:contains (' aaa ')") find all DIV elements that contain AAA


2.:empty () matches all empty elements that do not contain child elements or text
$ ("Td:empty")


3.:has (selector) matches the element that contains the matching elements of the selector
$ ("Div:has (P)"). AddClass ("test");//Add a text class to all DIV elements that contain p elements


4.:p arent matches elements that contain child elements or text
$ ("td:parent");//Find all TD elements that contain child elements or text


Selector-Visibility:
1.:hidden matches all invisible elements, and the INPUT element's Type property is hidden.
$ ("Tr:hidden");//Find all the invisible TR elements


2.:visible matches all visible elements
$ ("tr:visible");//Find all visible TR elements


Selector-Properties:
1.[attribute] matches the element that contains the given property
$ ("Div[id]")//Find all DIV elements that contain ID attributes


2.[attribute=value] matches a given property as an element of a particular value
$ ("Input[name= ' username ']")/check all name=username input elements


3. [Attribute!=value] matches all elements that do not contain the specified property, or the property is not equal to a specific value
This selector is equivalent to: not ([Attr=value]), to match elements that contain specific attributes but not equal to a particular value, use [Attr]:not ([Attr=value])
$ ("input[name!= ' username ']")/lookup all Name!=username input elements


4. [Attribute^=value] matches the given property as an element starting with some value
$ ("input[name^= ' user")//Find all input elements with ' NEWWS ' started in name


5. [Attribute$=value] matches a given property as an element that ends with some value
$ ("input[name$= ' letter"])//Find all input elements with the end of ' letter ' in name


6. [Attribute*=value] matches the given property to an element that contains certain values
$ ("input[name*= ' Man")//Find all input elements containing ' man ' in name


7. [Selector1][selector2][selectorn] Composite Property selector, run to meet multiple conditions at the same time.
$ ("Input[id][name= ' Man ')")//contains id attribute, and name is man's


Selector-child element:
1.:nth-child (index/even/odd/equation) matches the nth child or parity element under its parent element
$ ("UL Li:nth-child (2)")//Find 2nd Li in each UL


2.: First-child matches the first child element
$ ("ul Li:first-child")//Find the first Li in each UL


3.:las-child matches the last child element
$ ("ul Li:last-child")//Find the last Li in the first UL


4.only-child If an element is the only child element in the parent element, it will be matched and will not be matched if the parent element contains other elements
$ ("ul Li:only-child")//Find in UL is the only child element of Li


Selector-form:
1.:input,: Text,:p Assword,: Radio,: checkbox,: Submit,: Image,: Reset,: button,: File
2.:hidden matches all invisible elements, or elements of type hidden


Selector-Form Object properties:
1.:enable matches all available elements
$ ("input:enabled")//Find all available input elements


2.:d isabled match all unavailable elements
$ ("input:disabled")//Match all unavailable elements


3.:checked matches all selected selected elements (check box, radio box, excluding option in select)
$ ("input:checked")//Find all selected check box elements


4.:selected matches all selected option elements
$ ("Select option:selected")//Find all selected option elements

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.