I'd like to retrieve all elements which start with a specific ID. After a short search, the solution appeared to be:
$('*[id^="foo_"]')
to select all elements with an ID starting with foo_
. Although this selector syntax is very logical, I was just wondering whether it is possible to do this in a more 'shorthand' way, like:
$('#foo_*');
Th开发者_开发百科is did not work, however. Is there support for wildcarting like this?
As far as I know, there's no native way to do this.
However, here is a filter that allows regular expressions to be used for selectors. It should suit you just fine.
The selector syntax is almost identical to CSS, in which * means all selectors, rather than a wildcard. There's no need to specify the * in this case: [id^="foo_"]
will act in the same way but with slightly less specificity.
No, it isn't. *
is a universal selector meaning "Any element", not a generic wild card. [id^="foo_"]
and *[id^="foo_"]
are identical (except for specificity considerations).
精彩评论