Select the id that begins and ends with certain values

CSS selectors have gone a long way from their beginnings. Today you have multiple choices to select elements in the page.
Today I needed to select all the elements with the id matching this regex:

fixed_string_(.*)_digit

But CSS doesn’t let regex. To do this, you can combine these two attribute selectors:

[id^=value] // Element with the id beginning with "value"
[id$=value] // Element with the id ending with "value"

So we have:

div[id^=fixed_string_][id$=_digit] {
  color: red;
}

Source https://css-tricks.com/attribute-selectors/


Posted

in

by

Tags:

Comments

Leave a Reply

%d bloggers like this: