Web Development with jQuery®

(Elliott) #1

(^496) ❘ APPENDIX B JQUERY SELECTORS
bapp02.indd 02/17/2015 Page 496
[attribute!=value] Selects all elements where the attribute does not have
the specifi ed value. For example, given the selector
[src!="about:blank"] all elements with a src attri-
bute that does not contain the value about:blank will
be matched.
[attribute^=value] Selects all elements where the attribute’s value begins
with the specifi ed string. One example might be the
selector [href^="https://"], which would match
all href attributes that reference a secure HTTP
connection.
[attribute$=value] Selects all elements where the attribute’s value ends
with the specifi ed string. For example, the selector:
[href$=".pdf"] matches all href attributes that link
to pdf documents (assuming there are no query string
parameters or URL fragments).
[attribute=value] Selects all elements where the attribute’s value con-
tains the specifi ed string anywhere within the value. If
you were searching for href attributes that might have
query string permanents or URL fragments, you could
use the selector [href
=".pdf"] to fi nd PDF docu-
ments where the string ".pdf" might occur somewhere
within the attribute’s value.
[attribute~=value] Selects all elements where the attribute’s value con-
tains the specifi ed word. This is useful for situations
like class names where there are multiple values sepa-
rated by spaces. This selector is intended to match one
space-separated value. Take, for example, this selector:
[class~="selected"]; this selector would match the
following attribute:
class="disabled selected bodyContainer".
[href][title][class]
[target]
Selects all elements where the element has each attri-
bute. In this example, any element that contains all four
attributes, href, title, class, and target, would be
matched. Chaining attribute selectors works with any
type of attribute selector mentioned here, so you can
test if an attribute is present, if another attribute con-
tains a particular value, and if another attribute begins
with a value, and so on.
(continued)
http://www.it-ebooks.info

Free download pdf