How does jquery get the first or last child element?

Source: Internet
Author: User
Tags button type

How does jquery get the first or last child element? Through the Children method, children ("Input:first-child")$( This). Children ("Input:first-child"). Val (); $ ( This). Children ("Input:last-child"). Val ();> Selector, $ (". Items>input:first"in this article, we'll turn to a "jquery selection method Encyclopedia" http://wen.io/epg1p01let's start with a few operations that are selected by location:: First: By default it is relative to the entire page, such as: Li:first represents the first LI element of the entire page, and UL Li:first represents the first LI element of the entire page, and is a sub-element under the UL; Last: Ibid., just a final one.: First-Child: Matches the first sub-element, such as li:first-, for each parent elementChild Returns the first LI element of each ul. It can be understood that the elements of the page have the same parent element, and that it contains the LI element, then take the first LI element, each sub-class collection will be judged until all the required Li elements are found;: last-Child : This is also relative to the above, just take the last one;: Only-Child: Returns all elements that do not have a sibling node, note that the text element is not, that is, similar to the <div>hello<a href= "" &GT;JQUERY&LT;/A&GT;&LT;/DIV&GT; <a> elements; for $ ("label:only-child ") selects a LABEL element, and it is the label element of its parent's unique sub-element;: Nth-child (N): Returns the nth child node, n starts at 1, and if n takes 0, all elements are selected. such as: [*]li:nth-child (2) returns the Li element, and the element is the second child of its parent element;: Nth-child (even|odd): Returns an even or odd number of sub-nodes;: Nth-child (AN+B): Returns all child nodes that satisfy the an+b of an expression, such as 3n+1 Returns the child element where the parent node's PIP element is a multiple of 3 plus 1;: even: An even-numbered element within the page range, such as: Li:even returns all even-numbered Li elements;: odd: An odd-numbered element within the page range;: eq (n): Nth matched element (n starting from 0), such as: Li:eq (3) Returns the fourth Li element of the entire page, UL Li:eq (1returns the second LI element under the first UL element in the page, noting that only one match is returned;: GT (N): The element after the nth matched element (not included) (n starts with 0), such as: Ul:gt (2) returns all UL elements starting from the 3rd UL (including the third one);: LT (n): the element before the nth matching element (excluding) (n 0), such as: Ul:lt (2) return from No. 0 and 1th ul elements;2use CSS selector to select: element tag name: For example $ ("a") selects all linked elements; #id: Select by Element ID, for example $ ("#form1") selects the element with the ID Form1;. class: Select from the CSS class of the element, for example, $ (". Boldstyle"the CSS is selected as an element of the Boldstyle class, and the tag name #id.class: Selected by the id attribute and class attribute of a class element, such as: $ (a#blog.boldstyle) selects the ID for the blog and the CSS type A link element for the. Boldstyle type (<a id= ' blog ' class= '. Boldstyle ' >parent tag name Child tag name. Class: By selecting a child element of a CSS type under the parent tag, such as: $ (P a.redstyle), the link child element A in the p paragraph element is selected, and its CSS type is. redstyle;3Select through the child selector, the container selector and the property selector:*: Matches all elements, such as: $ (*) will return all elements of the page; e: Matches all elements of the tag named E, such as $ (A) returns all linked elements, E F: matches all child elements of the tag named F under the parent element E (F can be subclasses of the subclass of E, or even farther); e>f: Matches all direct child elements under the parent element e with the label named F; e+f: Matches all elements with the label named F, and the sibling node of type E precedes the f element (e,f next to each other); e~f: Match all elements in front of any sibling node E f (e,f not necessarily next to each other); E:has (F): match tag named E, with at least one descendant node with a label named F all elements E; e.c: matches all elements with class name C. C is equivalent to*. C; e#i: Matches all elements of ID I, E, #I等效于*#I; E[a]: Matches all elements with attribute A, E; E[a=v]: Match all attribute A with the value of V for element E; E[a^=v]: Matches all element E, and A's attribute value is v; e[a$=v]: Matches all element E, and A's attribute value is end of V; E[a*=v]: Matches all element E, and the attribute value of a contains V;4Select by using the jquery custom selector:: button: Select any element of the button type, including Input[type=Submit] etc;: checkbox: Select checkbox element;: File: Select all file type elements, i.e. Input[type=file];: Image: Select the element in the form, that is, the Input[type=Image ], note here and before based on tag name img Select Image a little different Kazakhstan;: Input: Select form elements, such as<input>,<select>,<textarea>,<button>Radio: Select a radio button element;: Reset: Select the reset button element, such as Input[type=reset],button[type=Reset];: Submit: Select the submit button element;: Text: Select the textual field element, i.e. Input[type=text];: animated: Select the element that is currently under dynamic control;: Contains (hello): Select the element that contains the text Hello;: header: Select the header element, as;:p arent: Select elements that have descendant nodes (including text), and exclude empty elements;: Selected: Select selected option elements;: visible: Select elements of Visibility;: Enable: Select form elements that are already available on the interface;:d isabled: Select the form element that is disabled on the interface;: Checked: Select the selected check box or radio button;

Turn from: http://blog.csdn.net/u010227447/article/details/45484033;

How does jquery get the first or last child element?

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.