jquery Selector Grooming

Source: Internet
Author: User

jquery Object interview:

1. Each (callback): Runs a function with each matching element as the context, return false, Stop the loop, return True, and jump to the next loop.
Here's an example:
$ ("img"). each (function () {
$ (this). Toggle ("example");
})

2.size () is the same as length, which returns the number of elements in a jquery object.
$ ("img"). Size (), or $ ("img"). length;

3.get (): Gets a collection of all matching DOM elements (note that the return is a DOM object, not a jquery object)
$ ("img"). Get (). reverse ();

4.get (Index): Gets one of the matching elements. Index means matching the first few elements, allowing you to manipulate an actual DOM element.
$ ("img"). Get (0);//Get the first matching IMG element
$ (this). Get (0) and $ (this) [0] equivalent

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

Selector-Basic:
selector1,selector2,selectorn returns the matched elements together, returning the
$ ("Div,span,p.myclass");

selector-level:
1.ancestor descendant matches all descendant elements under a given ancestor element
    $ ("div Input "),//div all input

2.parent > Child matches all children under the given parent element
    $ ("div > Input);//child element under parent element

3.prev + next matches all the next elements immediately following the Prev element
$ ("div + span")// The span

4.prev ~ siblings immediately after the Div matches all siblings elements after the prev element



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
In Ps:jquery 1.3, complex selectors have been supported (e.g.: not (div a) and: not (Div,a))
$ ("Input not (: checked)")//INPUT element with all unselected

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

5.:odd matches all elements with an odd index value, counting 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 line

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 heading element such as H1,h2,h3
$ (": Header"). CSS ("Background", "red");//full caption plus background color

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

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

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

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

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 type attribute of the INPUT element is hidden.
$ ("Tr:hidden");//Find all the non-visible TR elements

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

Selector-Properties:
1.[attribute] matches the element that includes the given attribute
$ ("div[id]")//Find all DIV elements that contain the id attribute

2.[attribute=value] matches a given property is an element of a particular value
$ ("input[name= ' username ')"//Search all Name=username INPUT element

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

4. [Attribute^=value] matches a given property is an element that starts with some value
    $ (" input[name^= ' user ')//Find all the input elements that have the name start with ' NEWWS '

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

6. [Attribute*=value] matches the given attribute to include elements of some value
   $ ("input[name*= ' man ')"//Find all the input elements of name including ' Man '

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

selector-child element:
Span style= "Background-color: #ffffff;" >1.:nth-child (index/even/odd/equation) matches the nth sub-or odd-even element under its parent element
    $ ("ul Li:nth-child (2)")// Find the 2nd Li
in each UL

2.: First-child matches 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 last Li in the first UL

4.only-child assumes that an element is the only child element of the parent element, it will be matched, assuming that the parent element contains other elements and will not be
$ ("ul Li:only-child")//In UL find 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 match all available elements
$ ("input:enabled")//Find all the 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, option not included 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

jquery Selector Grooming

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.