The similarities and differences between CSS selector and jquery selector: some special selectors

Source: Internet
Author: User
Tags button type

In the selector syntax defined by the CSS3 selector, jquery supports a fairly complete set of subsets, while also adding some non-standard but useful pseudo-classes. Here are some of the jquery extension selectors: (from http://www.cnblogs.com/MaxIE/p/4078869.html)

jquery Selection Filter
Filter filters Meaning
#id Match the id attribute to an element of ID. In a valid}itml document, more than one element will never appear with the same ID, so the filter is typically used as a standalone selector
. class Matches the class attribute (a list of words parsed into spaces) containing all the elements of a class word
[attr] Match all elements that have the attr attribute (and value independent)
[Attr=val] Match all elements that have the attr attribute and a value of Val
[Attr!=val] Matches all elements that do not have the attr attribute, or the value of the Attr property is not Val (extension of jquery)
[Attr^=val] element that matches the attr attribute value starting with Val
[Attr$=val] Elements that match the value of the Attr property to Val-end
[Attr*=val] Match attr attribute value contains Val element
[Attr~=val] Matches the element that contains the word Val when its Attr property is interpreted as a space-delimited list of words. So the selector "Div.note" is the same as "div [Class~=note]"
[Attr|=val] Match attr attribute value begins with Val and no other characters are followed, or other characters are elements that begin with a hyphen
: Animated Matches the element in the animation that was created by jquery
: button Match <button type= "button" > and <input type= "button" > element (Extension of jquery)
: checkbox Match <input type= "checkbox" > Element (Extension of jquery), which is more efficient when explicitly prefixed with the input tag "Input:checkbox"
: Checked Match the selected INPUT element
: Contains (text) Matches the element that contains the text of the specified text (the extension of jquery). The parentheses in the filter determine the range of the text-without adding quotation marks. The text of the filtered element is determined by the textcontent or innertext attribute-This is the original document text, without tags and annotations
:d isabled Match a disabled element
: Empty Match elements with no child nodes, no text content
: Enabled Match elements that are not disabled
: EQ (N) Matches the nth element in the selected list based on the document order, starting at 0 (extension of jquery)
: Even The element that matches even numbers in the list. Since the ordinal of the first element is 0, the 1th, 3rd, 5th, and so on are actually selected (extension of jquery)
: File Match <input type= "file" > element (Extension of jquery)
: First Matches the first element in a list. Same as ": eq (0)" (Extension of jquery)
: First-child The matching element is the first child element of its parent node. Note: This differs from ": First"
: GT (N) Matches an element with an ordinal greater than N in the selected list based on the document order, starting at 0 (extension of jquery)
: Has (SEL) Matched elements have descendant elements that match the sel of the inline selector
: Header Match all head elements:
: Hidden Match all elements that are not visible on the screen: the offsetwidth and offsetheight of these elements are generally considered to be 0
: Image Match <input type= "image" > element. Note that the filter does not match the element (extension of jquery)
: input Match user input elements: <input>, <textarea>, <select> and <button> (jquery extensions)
: Last Matches the last element in the selected list (extension of jquery)
: Last-child The matching element is the last child element of its parent node. Note: This differs from ": Last"
: LT (N) Matches an element with an ordinal less than n in the selected list based on the document order, starting at 0 (extension of jquery)
: Not (SEL) Matching element does not match inline selector sel
: Nth (N) Same as ": EQ (n)" (Extension of jquery)
: Nth-child (N) The matching element is the nth child element of its parent node: Can be numeric, word even, word odd, or calculation formula. Use ": Nth-child (even)" to select elements that are ranked 2nd or 4th in the child elements of their parent node. Use ": Nth-child (Odd)" To select elements that are 1th, 3rd, and so on in the child elements of their parent node.
More commonly, n is a xn or x n+y formula, where x and y are integers and n is literal N. Therefore, you can use Nth-child (3n+1) to select the 1th, 4th, 7th and other elements.
Note that the number of the filter starts at 1, so if an element is the first child of its parent, it is considered an odd element, matching 3n+1 instead of 3n. To be distinguished from ": Even and": odd "filters, which match the sequence number starting with 0.
: Odd The element that matches the odd (starting 0) ordinal of the list. Note that the elements with ordinal 1 and 3 are the 2nd and 4th matching elements (the extension of jquery)
: Only-child Matches elements that are unique child nodes of their parent node
:p arent The match is the element of the parent node, which is the opposite of ": empty" (the extension of jquery)
:p Assword Match <input type= "password" > elements (Extension of jquery)
: Radio Match <input type= "Radio" > Element (Extension of J query)
: RESET Match <input type= "reset" > and <button type= "reset" > elements (jquery extensions)
: Selected Matches the selected <option> element. Use ": Checked" to select selected check boxes and radio boxes (jquery extensions)
: Submit Match <input type= "Submit" > and <button type= "Submit" > elements (Extension of jquery)
: Text Match <input type= "text" > elements (Extension of jquery)
: Visible Matches all currently visible elements: the offsetwidth and offsetheight values of these elements are generally considered to be not 0, which is the opposite of ": hidden"

Note: Some of the selectors listed in the table accept parameters in parentheses. For example, the element selected by the following selector is ranked 1th or 2nd in the child elements of its parent node, so long as they contain "JavaScript" words, they do not contain elements.

P:nth-child (3n+1): Text (JavaScript): Not (: Have (a))

In general, specifying a label type prefix can make the filter run more efficiently. For example, instead of simply using ": Radio" to select a Radio box button, it would be better to use "Input:radio". An exception is the ID filter, which is more efficient when no tag prefix is added. For example, the selector "#address" is usually more efficient than a more explicit "form#address".

The similarities and differences between the

CSS selector and the jquery selector: some special selectors

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.