jQuery in Action

22
CHAPTER 2
Creating the wrapped element set
parent of the sublists
<li>
elements don't have the class
myList
, as shown in the
Lab results of figure 2.4.
Attribute selectors are also extremely powerful. Say we want to attach a special
behavior only to links that point to locations outside our sites. Let's take another
look at a portion of the Lab example that we previously examined:
<li><a href="http://jquery.com">jQuery supports</a>
<ul>
<li><a href="css1">CSS1</a></li>
<li><a href="css2">CSS2</a></li>
<li><a href="css3">CSS3</a></li>
<li>Basic XPath</li>
</ul>
</li>
What makes the link pointing to an external site unique is the presence of the
string
http://
at the beginning of the value of the link's
href
attribute. We could
select links with an
href
value starting with
http://
with the following selector:
a[href^=http://]
This matches all links with an
href
value beginning with exactly
http://
. The caret
character (
^
) is used to specify that the match is to occur at the beginning of a value.
This is the same character used by most regular expression processors to signify
matching at the beginning of a candidate string; it should be easy to remember.
Visit the Lab page, from which the example
HTML
fragment was lifted, type
a[href^=http://]
into the text box, and click Apply. Note how only the jQuery
link is highlighted.
There are other ways to use attribute selectors. To match an element that pos-
sesses a specific attribute, regardless of its value, we can use
form[method]
Figure 2.4 With the selector
ul.myList
>
li
>
a
, only the direct children of parent nodes
are matched.


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

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

OK

Loading...
...
Закрыть