Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 4
    Cool info. Only caveat is if performance is an issue, most CSS linters will reject attribute selectors that resemble regex (e.g. using '*') b/c of slow performance. With the exception of using a preprocessor (e.g. Sass), is there any other possible way of doing this? Commented Sep 29, 2014 at 13:45
  • 4
    Is there a way to check if the class attribute contains multiple substrings? Maybe something like div[class*="foo"][class="bar"]? Commented Jun 22, 2017 at 14:30
  • That space in our "contains" example is pretty killer. From what I can see, it shouldn't be there, correct? Commented Aug 14, 2017 at 19:49
  • 3
    @Thomas That is required to ensure class="foo tocolor-red" matches, but not class="foo fromtocolor-red-blue" Commented Sep 28, 2018 at 21:02
  • Thanks for this. I've been using this technique for a few years, but never realized that class^= only applies to the beginning of the HTML class entry. I thought it applied to all class names defined for the HTML tag. Commented May 2, 2019 at 15:04