If I am understanding your question correctly, you are trying to select all elements whose id starts with subtab-
followed by a number, followed by -sub
followed by another number. It also sounds like you want this selector to not match #subtab-1
, only things that have a suffix like #subtab-1-sub1
.
This cannot be done with CSS. CSS does not supply a selector that will allow wildcards. You can however hack something together that comes pretty close.
Hacky selector that might work
[id^="subtab-"][id*="-sub"]
would match any id that starts with subtab-
and also contains -sub
somewhere in the id. This will probably work but could cause false positives on things like #subtab-1-subtle
or #subtab-something-sub2
, #subtab-sub
, etc.
Another hacky selector that might work
Making the assumption that #subtab-?-sub?
elements are always contained inside of #subtab-?
elements and that #subtab-?
elements can never contain another #subtab-?
element, you could use the child combinator to target them: [id^="subtab-"] > [id^="subtab-"]
Relying on a class instead
A better solution would probably be to give all of the elements you are trying to target a common class, for instance <div class="subtab-sub">
, then selecting them all would be as easy as .subtab-sub
. Using a class would also yield much faster performance than using attribute selectors.