Styling input tags using their IDs can be very convenient due to the higher precedence weight they hold compared to classes.
For instance, I set a default width for input.text elements within a specific container:
.details .metadata input.text { width: 200px; }
When adjusting the width for a particular page, using the ID is more efficient than using the long selector mentioned above:
#my_input { width: 150px; }
Now imagine that I have automatically generated input fields in my app (created using form_for
and nested_attributes_for
in Ruby On Rails) with IDs like:
#event_rules_attributes_0_interval
#event_rules_attributes_1_interval
#event_rules_attributes_2_interval
...and so on...
and
#event_rules_attributes_0_count
#event_rules_attributes_1_count
#event_rules_attributes_2_count
...and so on...
In this case, I would need to use an ID selector that starts with "event_rules_attributes_" AND ends with "_count" or one that starts with "event_rules_attributes_" AND ends with "_interval". While I am aware of the existence of the [id$=] and [id^=] matchers, I wonder if there is a way to combine them?