jQuery in Action

24
CHAPTER 2
Creating the wrapped element set
With all this knowledge in hand, head over to the Selectors Lab page, and spend
some more time running experiments using selectors of various types from
table 2.1. Try to make some targeted selections like the
<span>
elements contain-
ing the text Hello and Goodbye (hint: you'll need to use a combination of selectors
to get the job done).
As if the power of the selectors that we've discussed so far isn't enough,
there are some more options that give us an even finer ability to slice and dice
the page.
2.1.3 Selecting by position
Sometimes, we'll need to select elements by their position on the page or in rela-
tion to other elements. We might want to select the first link on the page, or every
other paragraph, or the last list item of each list. jQuery supports mechanisms for
achieving these specific selections.
Table 2.1 The basic CSS Selectors supported by jQuery
Selector
Description
*
Matches any element.
E
Matches all element with tag name E.
E F
Matches all elements with tag name F that are descendents of E.
E>F
Matches all elements with tag name F that are direct children of E.
E+F
Matches all elements F immediately preceded by sibling E.
E~F
Matches all elements F preceded by any sibling E.
E:has(F)
Matches all elements with tag name E that have at least one descendent with tag name F.
E.C
Matches all elements E with class name C. Omitting E is the same as *.C.
E#I
Matches element E with id of I. Omitting E is the same as *#I.
E[A]
Matches all elements E with attribute A of any value.
E[A=V]
Matches all elements E with attribute A whose value is exactly V.
E[A^=V]
Matches all elements E with attribute A whose value begins with V.
E[A$=V]
Matches all elements E with attribute A whose value ends with V.
E[A*=V]
Matches all elements E with attribute A whose value contains V.


Другие страницы

 
Cкачать книги бесплатно без регистрации в электронном виде (pdf, chm, txt).Вы можете читать книги онлайн на нашем сайте литературного портала книг.Большая подборка учебников, пособий, интересных книг.Электронные книги на английском языке скачать бесплатно без смс.