Spry

Supported selectors

The Spry Element Selector supports the following selectors:

Selector pattern

Description

E

an element of type E (for example div, p, etc.)

E.className

an E element with a specified classname

E#id

an E element with ID equal to "id".

E F

an F element descendant of an E element

*

any element

E:first-child

an E element, first child of its parent

E[foo]

an E element with a "foo" attribute. Note: When using E[class], this will fail on Internet Explorer, since it adds a class attribute to every element, even those with out a class in the markup. This is a browser issue and not a Spry issue.

E > F

an F element child of an E element

E[foo~="bar"]

an E element whose "foo" attribute value is a list of space-separated values, one of which is exactly equal to "bar"

E[hreflang|="en"]

an E element whose "hreflang" attribute has a hyphen-separated list of values beginning (from the left) with "en"

E[foo="bar"]

an E element whose "foo" attribute value is exactly equal to "bar"

E + F

an F element immediately preceded by an E element

E[foo$="bar"]

an E element whose "foo" attribute value ends exactly with the string "bar"

E:last-child

an E element, last child of its parent

E:nth-last-of-type(n)

an E element, the n-th sibling of its type, counting from the last one

E:nth-of-type(n)

an E element, the n-th sibling of its type

E[foo^="bar"]

an E element whose "foo" attribute value begins exactly with the string "bar"

E:nth-last-child(n)

an E element, the n-th child of its parent, counting from the last one

E:empty

an E element that has no children (including text nodes)

E:nth-child(n)

an E element, the n-th child of its parent

E:only-of-type

an E element, only sibling of its type

E:not(s)

an E element that does not match simple selector s

E:only-child

an E element, only child of its parent

E:last-of-type

an E element, last sibling of its type

E:first-of-type

an E element, first sibling of its type

E[foo*="bar"]

an E element whose "foo" attribute value contains the substring "bar"

E ~ F

an F element preceded by an E element

E:checked

an E element that is checked (radio buttons or checkboxes)

E:disabled

an E element that is set at disabled (form elements)

E:enabled

an E element that is enabled (form elements that are not explicitly disabled.)

These selectors can be combined to achieve a more flexible or specific selection. For example, the following selector combines several selectors to ultimately select the div that’s assigned a “product” class, and has a title attribute that is equal to the string "Dreamweaver", but only if it is the first child element of its parent:

Spry.$$("div.product[title=Dreamweaver]:first-child");

Likewise, you can combine multiple selectors into a sequence with a comma, just as you can in a CSS rule. The following example selects all the divs the previous example selects, and also selects any span tags with a class of "name":

Spry.$$("div.product[title=Dreamweaver]:first-child, span.name");

The Spry Element selector does not support the following selectors:

Selector pattern

Description

E:link

E:visited

an E element being the source anchor of a hyperlink of which the target is not yet visited (:link) or already visited (:visited)

E:active

E:hover

E:focus

an E element during certain user actions

E::first-line

the first formatted line of an E element

E::first-letter

the first formatted letter of an E element

E::before

generated content before an E element

E::after

generated content after an E element

E:target

an E element being the target of the referring URI

E:lang(fr)

an element of type E in language "fr". The document language specifies how language is determined.

E::selection

the portion of an E element that is currently selected/highlighted by the user

According to the W3C spec, spaces are generally not allowed within the selector except when they are part of the actual selector. For example:

Spry.$$("DIV P").addClassName("redText"); Correct.
Spry.$$("p[class~=dev]").setAttribute("align", "left"); Correct.
Spry.$$("p[class ~= dev]").setAttribute("align", "left"); Not
correct.