Prototype in the selector mainly support tag Selector, class selector and ID selector, as well as attribute selector, selector is the use of CSS selector to match the selection of page elements, So to understand selector should first understand the CSS selector, the following is the syntax of CSS2 selector, of course, many browsers just support a part of it, basically contains all the types we usually use
The following table summarizes CSS2 selector syntax, which can be seen in detail http://www.w3.org/TR/REC-CSS2/selector.html:
Pattern |
Meaning |
described in section |
* |
matches any element. |
Universal Selector |
E |
Matches any e-element (i.e., an element of type E). |
Type Selectors |
E F |
Matches any F-element is a descendant of the E element. |
Descendant selectors |
E > F |
Matches any F-element that is the child of the An element E. |
Child selectors |
E:first-child |
Matches element e When E is the "the" " |
The:first-child Pseudo-class |
E:link e:visited |
Matches element e If E is the source anchor of a hyperlink of which the target are not yet visited (: link) or already visit Ed (: visited). |
The link pseudo-classes |
E:active E:hover E:focus |
Matches E during certain user actions. |
The dynamic pseudo-classes |
E:lang (c) |
Matches element of type E if it is in (human) language C (the document language specifies how language is determined). |
The:lang () Pseudo-class |
E + F |
Matches any F element immediately preceded by a element E. |
Adjacent selectors |
E[foo] |
Matches any E-element with the "foo" attribute set (whatever the value). |
Attribute Selectors |
e[foo= "Warning"] |
Matches any E-element whose "Foo" attribute value is exactly equal to "warning". |
Attribute Selectors |
e[foo~= "Warning"] |
Matches any E-element whose "Foo" attribute value is a list of space-separated values, one of which are exactly equal to "W Arning ". |
Attribute Selectors |
E[lang|= "en"] |
Matches any E element whose "lang" attributes has a hyphen-separated list of values beginning (from the left) with "en". |
Attribute Selectors |
Div.warning |
HTML only. The same as div[class~= "warning"]. |
Class Selectors |
E#myid |
Matches any E-element ID equal to "myID". |
ID Selectors |
Selector contains selector objects and classes,
Selector also has several static methods, which are:
Matchelements (elements, expression): Returns a list of expression-compliant elements in elements
Findelement (elements, expression, index): Returns the element indexed as index in the list of elements that conform to expression in elements
Findchildelements (element, expressions): Find the list of elements in the descendant elements of the element that conform to expressions, where expressions is an array of expression, The expression supports the "Div li. #id" form
$$ method: Simply invoke return Selector.findchildelements (document, $A (arguments))
Although selector has so many methods, but most of them are internal calls, we are generally rarely used because we have a convenient way to $$, for most of the situation is enough
The Selector object has the following two methods:
Match (Element): Whether the element matches the selector, which is described in the element
Findelements (parentnode): A list of all descendants in ParentNode that match this selector
The use of the method is also very simple var s=new Selector (expression); S.match (Element); S.findelements ($ (element)), where expression can be "div", "#id", ". Class", "Div#id", "Div[attribute", "div[attribute= FFF] "," DIV[ATTRIBUTE!=SDF] "