How to select these elements
I'd like to handler all elements with the attribute rel
inside of an a
elemen开发者_运维百科ts that start with string lightbox
.
How can I do it with jQuery?
With the attribute-starts-with selector:
$('a [rel^="lightbox"]')
you need startswith selector
$('a[rel^="lightbox"]')
Use the attribute starts with selector.
$('a [rel^="lightbox"]')
EDIT: having re-read your question, it sounds like this may be what you want:
$('a[id^="lightbox"] [rel]')
This selects all elements that have the attribute rel
and are within an a
tag that has an ID starting with lightbox
.
Just to be different... if it is a prefix (i.e. "lightbox-") you can use the |=
selector.
$('a[rel|=lightbox]')
精彩评论