Wildcard in jQuery selector

I would like to get all items that start with a specific ID. After a short search, the solution turned out to be this:

$('*[id^="foo_"]')

to select all items with an identifier starting with foo_. Although this selector syntax is very logical, I'm just wondering if this can be done more "shortly", for example:

$('#foo_*');

However, this did not work. Is there any support for this category?

+5
source share
3 answers

As far as I know, there is no natural way to do this.

However, here is a filter that allows you to use regular expressions for selectors. This should suit you just fine.

+4

CSS, * , . *: [id^="foo_"] , .

+3

No, it is not. *is a universal selector, which means "Any element", not a universal wild card. [id^="foo_"]and *[id^="foo_"]identical (except for specificity ).

+2
source

All Articles